0

I'm trying to group posts from same day, the problem is that 2/20 gets grouped with 3/20 (20 = 20)

How can this be fixed?

This is my current code:

select day(Date), count(*) from Posts WHERE shopID != '' group by shopID, day(Date)

2 Answers 2

3

You need to group by every piece that might be different. So add MONTH(Date) and even YEAR(Date) depending on the scope of your query.

select DAY(Date), count(*) from Posts WHERE shopID != '' group by shopID, YEAR(Date), MONTH(Date), DAY(Date)
Sign up to request clarification or add additional context in comments.

Comments

0

You could also group this way: UNIX_TIMESTAMP(date(date)), instead of grouping by year, month and day separately

select date(date), count(*) from Posts
WHERE shopID != ''
group by shopID, UNIX_TIMESTAMP(date(date))

Note you'll have to also take the other date data in the select statement to be able to recognize which month/year the day belongs to. If you don't you'll get a lot of day numbers and counts, but the day numbers will be repeated for each month/year.

That's why I used date(date), count(*).

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.