MySQL count and group by day

后端 未结 4 1273
误落风尘
误落风尘 2020-12-11 16:51

I have the following structure

ID    DATE(DATETIME)         TID
1     2012-04-01 23:23:23    8882

I\'m trying to count the amount of rows a

相关标签:
4条回答
  • 2020-12-11 17:34

    You can group using the DAY function:

    SELECT DAY(Date), COUNT(*)
    FROM table
    WHERE TID = 8882
    GROUP BY DAY(Date)
    
    0 讨论(0)
  • 2020-12-11 17:46

    Not sure exactly what you mean by day of the month -- do you want to group the 1st of Feb with the 1st of March? Or do you just mean date? Assuming the latter, how about this:

    SELECT DATE(date) as d,count(ID) from TABLENAME where TID=8882 GROUP by d;
    
    0 讨论(0)
  • 2020-12-11 17:49

    Try this:

    SELECT DAY(date) AS `DAY`,  COUNT(1) AS `COUNT` FROM
    table1 
        WHERE TID = 8882
    GROUP BY DAY(date)
    

    What about MySQL Query GROUP BY day / month / year

    0 讨论(0)
  • 2020-12-11 17:52

    Try this query:

    SELECT COUNT(id), DAY(dat), MONTH(dat), YEAR(dat) 
    FROM table
    WHERE TID=8882
    GROUP BY YEAR(dat), MONTH(dat), DAY(dat);
    
    0 讨论(0)
提交回复
热议问题