答案 0 :(得分:4)
使用条件聚合。
select cast(weekdate as date),
sum(case when permittype = 0 then total else 0 end) as permittype0,
sum(case when permittype = 1 then total else 0 end) as permittype1
from tablename
group by cast(weekdate as date)
答案 1 :(得分:1)
我会使用条件聚合来做到这一点:
select weekdate,
sum(case when permittype = 0 then total else 0 end) as permitttype0,
sum(case when permittype = 1 then total else 0 end) as permitttype1
from followingdata t
group by weekdate
order by weekdate;
如果您愿意,也可以使用pivot
语法。