第1个回答 2014-12-17
行列转换, 试试这个:
select lrdate,orgid,pluid,
max(case when twtype='ps' then count end) ps,
max(case when twtype='pd' then count end) pd,
max(case when twtype='th' then count end) th
from tabname
group by lrdate,orgid,pluid
第2个回答 2014-12-17
对twtype进行行转列控制。
第3个回答 2014-12-17
select a.*,b.count,c.count from
(select lrdate, orgid,pluid,count from table1 where twtype='ps') a,
(select orgid,count from table1 where twtype='pd') b,
(select orgid,count from table1 where twtype='th') c
where a.orgid=b.orgid
and a.orgid=c.orgid
第4个回答 推荐于2017-09-19
MSSQL语句:
select lrdate,orgid,pluid,case when twtype = 'ps' then count else 0 end ps
,case when twtype = 'pd' then count else 0 end pd
,case when twtype = 'th' then count else 0 end th
from table
group by lrdate,orgid,pluid本回答被提问者和网友采纳