0

I have the following data:

enter image description here

In SQL Server How can I have group by weekdate so I have only one row for each weekdate, example for the weekdate 2015-11-14:

enter image description here

Any clue?

VAAA
  • 14,531
  • 28
  • 130
  • 253

2 Answers2

4

Use conditional aggregation.

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)
Vamsi Prabhala
  • 48,685
  • 4
  • 36
  • 58
1

I would do this using conditional aggregation:

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;

You can also use pivot syntax, if you prefer.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786