Count different values in a time span. The number of occurrences of the period. Here, I want to query the number of times that the periods field of each month has different values in one year. For example, in the-4 month, periods appears 3 times for 2 and 3 once for 3. The most important thing is periods. You don't know how many of them exist...
Count the number of occurrences of different values in the time span
Here, I want to query the number of times each month's periods field has different values in one year.
For example, in the-4 month, periods appears 3 times for 2 and 3 once for 3. The most important thing is that periods does not know how many possible values there are, maybe there is 1 in this month, maybe not.
Reply content:
Count the number of occurrences of different values in the time span
Here, I want to query the number of times each month's periods field has different values in one year.
For example, in the-4 month, periods appears 3 times for 2 and 3 once for 3. The most important thing is that periods does not know how many possible values there are, maybe there is 1 in this month, maybe not.
I wrote a DEMO to preview it online.
The Time Format I used is date,Year-month-day
This form
Count,Count and then group by column name
SELECT `periods`,DATE_FORMAT(time,'%Y-%m') as month,COUNT(*) AS `times` FROM `product` GROUP BY `periods`,`month` ORDER BY `month` DESC
DOC:
Date_format: http://www.w3school.com.cn/ SQL /func_date_format.asp
Group by: http://www.w3school.com.cn/ SQL/SQL _groupby.asp
Use the count function
Use two group by conditions.
Select count (id), periods, from_unixtime (time, '% Y-% m') from productwhere your condition group by periods, from_unixtime (time, '% Y-% m ')
Er, the general idea is like this.
Select periods, sum (periods) as count from product where month> = 'time' and mouth <= "time" group by periods