total count each day sorted, result grouped by week
My query looks like this right now pretty straightforward:
select
count(*),
date(visit_date),
DATE_FORMAT(visit_date,"%a")
from visits
group by date(visit_date)
Here is the result:
http://d.pr/FmMg
what I want 开发者_如何学运维to happen is:
- for each week the count is sorted
Can you modify my query so it satisfies the criteria?
Assuming, you no longer need the count by day and are ONLY looking for count by week:
SELECT
count(*),
yearweek(visit_date)
FROM visits
GROUP BY yearweek(visit_date)
ORDER BY yearweek(visit_date) ASC;
Are you trying to do like this? - you can use Datepart to get week number and sort by that.
select
count(*),
date(visit_date),
DATE_FORMAT(visit_date,"%a")
from
visits
group by
date(visit_date)
order by
datepart(yyyy,visit_date),
datepart(wk,visit_date),
count(*)
精彩评论