Tyralcori
Tyralcori

Reputation: 1047

Group a datetime by date - without time

Today I noticed, I may designed a table wrong - with lots of records ~1kk. My goal is to group these records by day (YYYY-mm-dd), but I only have a datetime (YYYY-mm-dd H:i:s) field.

Current query

SELECT COUNT(datetime), datetime FROM slowExecution group by datetime;

Is this even possible?

Upvotes: 0

Views: 142

Answers (1)

Mauricio Trajano
Mauricio Trajano

Reputation: 2927

Yes it is, with the date() function in sql which extracts the date from datetime so

SELECT COUNT(datetime), datetime FROM slowExecution group by DATE(datetime);

Upvotes: 3

Related Questions