This question is an exact duplicate:

How to select in the array and publish the data for the month from the database with a breakdown of data for each day? enter image description here

Reported as a duplicate by participants Alexey Shimansky , Community Spirit Jan 6 '17 at 10:19 .

This question has been marked as a duplicate of an existing one.

  • How do you imagine the breakdown? The base always returns a stream of rows of the same structure; a two-level structure is not provided. The database can aggregate your data for the month in one line, but in this case you need to clarify what you need to aggregate. - etki
  • The number of rows in the database with a date for example 20070106 and with a value of l in the field of lead - ivanov

1 answer 1

The following query will aggregate the number of records sought by day.

SELECT DATE(dt), COUNT(i) FROM leads WHERE lead = 'l' GROUP BY DATE(dt) 

http://sqlfiddle.com/#!9/5617d/2

The query will aggregate over the records that have the value l in the lead field, counting (the COUNT function) the number of such records for each day ( DATE(dt) ). Perhaps there are more optimal solutions, but most likely this request will be fulfilled in less than 100ms.

Additional conditions can be specified using the HAVING operator, which works in a way similar to WHERE , but operates on aggregated data.

Please check out the question next time so that you can understand from it what you want. Now this is not.

  • Thank! Additional question, such tables with different titles 4 how to make a request to all at once? - ivanov
  • @ivanov is a question from the category of "how to transport four families to Moscow." I do not know your families, what they have with the documents, where they are now, and where they should be geographically located in Moscow. - etki