12

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 and group them by each day of the month that matches TID = 8882

Thanks

3
  • 1
    possible duplicate of MySQL Query GROUP BY day / month / year Commented May 1, 2012 at 8:47
  • 2
    Have u tried anything? or u r just waiting for whole code? and what do u mean by group them by each day? u mean group by date? Commented May 1, 2012 at 8:48
  • when you say "group by day" ... do you mean all items within a single date ? or you want to group items that fall into the same day of the month of different months (e.g. 1 Jan and 1 Feb, and 1 March together) ? Commented May 1, 2012 at 8:51

5 Answers 5

21

You can group using the DAY function:

SELECT DAY(Date), COUNT(*)
FROM table
WHERE TID = 8882
GROUP BY DAY(Date)
Sign up to request clarification or add additional context in comments.

1 Comment

this helped me a lot I was missing the Day() rapper. I actually needed date(), but your answer led me to my solution. +1
10

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;

Comments

4

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);

Comments

3

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

Comments

3

count for every date:

SELECT date(created_at), COUNT(*)
FROM message_requests
GROUP BY date(created_at)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.