select (select SUM(fraction) from test88 where isType=1 and CONVERT(varchar(10),a.operateTime,20)=CONVERT(varchar(10),operateTime,20)) 增加, (select SUM(fraction) from test88 where isType=2 and CONVERT(varchar(10),a.operateTime,20)=CONVERT(varchar(10),operateTime,20)) 增加, [operateTime] 时间 from test88 a这样查就行
感觉有点难懂,Mark一下再说。
try this,select sum(case when isType=1 then fraction else 0 end) '增加', sum(case when isType=2 then fraction else 0 end) '减少', convert(varchar(10),operateTime,20) '时间' from test88 group by convert(varchar(10),operateTime,20)
select
(select SUM(fraction) from test88
where isType=1 and
CONVERT(varchar(10),a.operateTime,20)=CONVERT(varchar(10),operateTime,20)) 增加,
(select SUM(fraction) from test88
where isType=2 and
CONVERT(varchar(10),a.operateTime,20)=CONVERT(varchar(10),operateTime,20)) 增加,
[operateTime] 时间 from test88 a这样查就行
sum(case when isType=2 then fraction else 0 end) '减少',
convert(varchar(10),operateTime,20) '时间'
from test88
group by convert(varchar(10),operateTime,20)