0

I have a table:

Name         Registered Date
Amit         2017-01-01
Akshay       2017-01-03
Ankith       2017-01-05
Amit         2017-01-12
Amit         2017-01-13
Amit         2017-02-01
Amit         2017-02-01

I want to write a query which will display the registration weekly report: Say date between 2017-01-01 to 2017-03-01

Week          Count
2017-01-01    3
2017-01-08    2
2017-01-15    0
2017-01-22    0
2017-01-29    2
2017-02-05    0
2017-02-12    0
2017-02-19    0
2017-02-26    0

Here Count is the number of people who registered that week. 3 people registered in between 2017-01-01 to 2017-01-07. So which query i have to use for this result?

Thanks

Boneist
  • 22,910
  • 1
  • 25
  • 40

1 Answers1

0

If you can use the WEEK function and display the week number instead of a date, then:

select dummy.n, count(table.RegiseredDate)
from (SELECT 1 as n UNION SELECT 2 as n UNION SELECT 3 as n ... UNION SELECT 53 as n) dummy 
     left outer join table on dummy.n=WEEK(table.Registered Date)
where start_date>= x and end_date<= y
group by WEEK(Registered Date)
Asier Azkuenaga
  • 1,199
  • 6
  • 17