qyx0714 2015-02-09 01:00 采纳率: 50%
浏览 2118
已采纳

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

结果如下:图片说明

  • 写回答

2条回答 默认 最新

  • WorldMobile 2015-02-11 00:38
    关注

    比如你这个表为table,列为fritemcd,qty,qty2 你可以这么写

    select gritemcd, qty, 0 qty2 from table
    union all
    select gritemcd, 0, qty2 from table

    再加上你的条件即可

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?