1 select * from 2 (select count(*) as '计划任务' from hscdm_project_qc where task_date BETWEEN date_add(now(),interval -7 DAY ) and NOW() ) as t1, 3 (select count(*) as '报送数据' from hscdm_project_qc where task_status =2 and task_date BETWEEN date_add(now(),interval -7 DAY ) and NOW() )as t2, 4 (select count(*) as '审核通过' from hscdm_project_qc where check_status=1 and task_date BETWEEN date_add(now(),interval -7 DAY ) and NOW() ) as t3
服务器端和客户端都好
count(case when .. then ... end)
SELECT COUNT(1) AS '计划任务', COUNT(CASE WHEN TASK_STATUS = 2 THEN 1 END) AS '报送数据', COUNT(CASE WHEN TASK_STATUS = 1 THEN 1 END) AS '审核通过' FROM HSCDM_PROJECT_QC WHERE TASK_DATE BETWEEN DATE_ADD(NOW(), INTERVAL - 7 DAY) AND NOW()
哪里需要优化呢?
大部分内容都是一样的 就只有个别条件不同 想看看能不能优化一下
可以试下 case 。。。。 then 。。。when语句