SQL查询语句行转列横向显示

在SQL查询语句行转列横向显示中access中没有CASE,要用IIF代替

select  iif(sex= '1 ', '男 ', '女 ')  from  tablename


select country, sum(case when type='A' then money end) as A,
sum(case when type='B' then money end) as B,
sum(case when type='C' then money end) as C
from table1
group by country



select b.MemberName,
count(b.MemberName),
SUM(case when CONVERT(varchar(7),a.CreateTime,120)='2016-01' then a.PayAmount end) as '2016-01',
SUM(case when CONVERT(varchar(7),a.CreateTime,120)='2016-02' then a.PayAmount end) as '2016-02',
SUM(case when CONVERT(varchar(7),a.CreateTime,120)='2016-03' then a.PayAmount end) as '2016-03',
SUM(case when CONVERT(varchar(7),a.CreateTime,120)='2016-04' then a.PayAmount end) as '2016-04',
SUM(case when CONVERT(varchar(7),a.CreateTime,120)='2016-05' then a.PayAmount end) as '2016-05',
SUM(case when CONVERT(varchar(7),a.CreateTime,120)='2016-06' then a.PayAmount end) as '2016-06',
SUM(case when CONVERT(varchar(7),a.CreateTime,120)='2016-07' then a.PayAmount end) as '2016-07',
SUM(case when CONVERT(varchar(7),a.CreateTime,120)='2016-08' then a.PayAmount end) as '2016-08',
SUM(case when CONVERT(varchar(7),a.CreateTime,120)='2016-09' then a.PayAmount end) as '2016-09',
SUM(case when CONVERT(varchar(7),a.CreateTime,120)='2016-10' then a.PayAmount end) as '2016-10',
SUM(case when CONVERT(varchar(7),a.CreateTime,120)='2016-11' then a.PayAmount end) as '2016-11',
SUM(case when CONVERT(varchar(7),a.CreateTime,120)='2016-12' then a.PayAmount end) as '2016-12',
SUM(case when CONVERT(varchar(7),a.CreateTime,120)='2017-01' then a.PayAmount end) as '2017-01',
SUM(case when CONVERT(varchar(7),a.CreateTime,120)='2017-02' then a.PayAmount end) as '2017-02'
from PartInChina_cn.dbo.ORD_Purchase a
join PartInChina_cn.dbo.ORD_Sales b on a.PNO=b.PO_NO
left join PartInChina_cn.dbo.ORD_RefundAudit c on a.PNO=c.PNO
where a.CreateTime>'2016-1-1' and a.CreateTime<'2017-3-1'
and a.Status>=3 and a.Status!=11 and a.OrderType in (0,2) and c.PNO is null
group by b.MemberName

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值