问题描述
- SQL 列转行如何实现?
-
这种什么实现?我的语句是:select ISNULL(fritemcd,tofritemcd)as fritemcd, qty,qty2 from
(SELECT a.fritemcd,a.qty FROM iniop03t a
left join biitm01t b on fritemcd=itemcd
WHERE a.movedt='20150204' AND a.frstockcd IN ('A710','A711','A713','a712' )and b.itemkind='2') T
full join
(SELECT a.fritemcd tofritemcd,a.qty as qty2 FROM iniop03t a --入
left join biitm01t b on fritemcd=itemcd
WHERE movedt='20150204' AND tostockcd IN ('A710','A711','A713','a712') and b.itemkind='2')F on T.fritemcd=F.tofritemcd
解决方案
比如你这个表为table,列为fritemcd,qty,qty2 你可以这么写
select gritemcd, qty, 0 qty2 from table
union all
select gritemcd, 0, qty2 from table
再加上你的条件即可
解决方案二:
再加个排序条件,即达达你的要求
时间: 2024-09-29 04:31:25