多 多多帮助 Unregistered / Unconfirmed GUEST, unregistred user! 2009-02-04 #1 有仓库表数据如下:仓库一仓库二库存表仓库一 铅笔 10仓库二 铅笔 5仓库一 钢笔 6仓库二 钢笔 0怎么查询取得以下结果商品 仓库一 仓库二铅笔 10 5钢笔 6 0谢谢
A asnychen Unregistered / Unconfirmed GUEST, unregistred user! 2009-02-04 #3 自己写代码去转换吧,很简单的。。以前有的帖子提过这个问题,你可以看下
浪 浪人情哥 Unregistered / Unconfirmed GUEST, unregistred user! 2009-02-05 #5 我曾经回答过,好象是什么DBA的面试题目,你看看我回答的问题就知道了
F fhuibo Unregistered / Unconfirmed GUEST, unregistred user! 2009-02-05 #6 行专列问题:假如你的字段名分别为 cangku leibie shuldeclare @sql nvarchar(4000)set @sql = 'select leibie 'select @sql = @sql + ' ,sum(case cangku when '''+cangku +''' then shul else 0 end) '''+cast (cangku as varchar(10))+ '''' from (select distinct (cangku) as cangku from zzz ) a select @sql = @sql + ' from zzz group by leibie'print @sqlexec(@sql)
行专列问题:假如你的字段名分别为 cangku leibie shuldeclare @sql nvarchar(4000)set @sql = 'select leibie 'select @sql = @sql + ' ,sum(case cangku when '''+cangku +''' then shul else 0 end) '''+cast (cangku as varchar(10))+ '''' from (select distinct (cangku) as cangku from zzz ) a select @sql = @sql + ' from zzz group by leibie'print @sqlexec(@sql)