2015-11-20 67 views

回答

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) 
+0

@ FuzzyTree ..我錯過了..謝謝 –

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語法,如果你喜歡。