开发者

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:

  1. 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(*)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜