SELECT
DATE_FORMAT (CREAT_DATE, '% % Y - m),
The SUM (PROPERTY_VALUE)
The FROM
(SELECT
*
The FROM
S_water
WHERE CREAT_DATE BETWEEN DATE_SUB (NOW (), INTERVAL 5 MONTH)
AND NOW ()) AS a
GROUP BY DATE_FORMAT (CREAT_DATE, '% Y - % m')
So calculate words will elevate the monthly data are calculated, I don't want to filter out the last data
CodePudding user response:
Select *The from TB A
Where not the exists (select 1 from TB where device_code=a. d. evice_code and create_date & lt; A.c reate_date)
CodePudding user response:
Select the id FROM s_water where CREAT_DATE & gt; DATE_SUB (NOW (), INTERVAL 6 MONTH) group by id, DATE_FORMAT (CREAT_DATE, '% Y - % m) order by CREAT_DATE descSo you can get a month in the end, a record ID