开发者

total count each day sorted, result grouped by week

开发者 https://www.devze.com 2023-04-01 05:08 出处:网络
My query looks like this right now pretty straightforward: select count(*), date(visit_date), DATE_FORMAT(visit_date,\"%a\")

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

精彩评论

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

关注公众号