Home > Back-end >  Inquired of god, the last ten days of data write SQL statements?
Inquired of god, the last ten days of data write SQL statements?

Time:04-23

Requirements: students' attendance statistics in recent 10 days,

Question is: when one day no data to display the date and the number is 0,

I now the SQL statement is such, only have the date of the data and the data will be shown, please everyone a great god help me to optimize it,
 
SELECT
DATE_FORMAT (deta. TIME, 'Y - m - % d % %) AS a dateTime,
The sum (CASE WHEN deta. STATUS='6' THEN '1' ELSE '0' END) leaveAmount,
The sum (CASE WHEN deta. STATUS='1' THEN '1' ELSE '0' END) attendanceAmount
The FROM
Tb_detail deta
WHERE
DATE_SUB (CURDATE (), the INTERVAL of 10 DAY & lt;=the date (deta. TIME)
GROUP BY
DateTime
The ORDER BY
DateTime ASC

CodePudding user response:

Code with the no? Why don't want to put the logic in SQL

CodePudding user response:

What SQL processing and code simply passthrough, so do you think what is the meaning of Java code
  • Related