Home > database >  How MySQL query table each time point table data in total
How MySQL query table each time point table data in total

Time:10-29

Needs to query each time point corresponding to the total data in the table, such as the 2020-01-01 12:00:00 schedule according to the total amount is 100000, 2020-01-01 14:00:00 schedule according to the total amount of 150000
How to query and returns the time point and the corresponding according to total quantity?

CodePudding user response:

The select date_format (date, '% Y - m - H % d % %') as d, count (*) as CNT
From the table
Group by d

CodePudding user response:

reference 1st floor csdn_castiel response:
select date_format (date, '% Y - m - H % d % %') as d, count (*) as CNT
From the table
Group by d

Thank you for your reply, but the amount of data need to lookup table, is not the amount of each hour

CodePudding user response:

refer to the second floor of the pursuit of a dream small white reply:
thank you for your reply, but the amount of data need to lookup table, not the amount of each hour ha



Select d, (select count (*) from the table where a. d. & gt; Y=date_format (date, '% - m - H % d % %')) as the from CNT
(select date_format (date, 'Y - m - H % d % % %') d
From the table group by d) a

CodePudding user response:

reference csdn_castiel reply: 3/f
Quote: refer to the second floor of the pursuit of a dream small white reply:

Thank you for your reply, but the amount of data need to lookup table, not the amount of each hour ha



Select d, (select count (*) from the table where a. d. & gt; Y=date_format (date, '% - m - H % d % %')) as the from CNT
(select date_format (date, 'Y - m - H % d % % %') d
From the table group by d) a

Thank you for your answer, has been solved, thank you very much!
  • Related