count(case OrgName when '成型车间' then EmployeeCode else 0 end)
时间: 2023-12-30 09:23:01 浏览: 97
这段代码的作用是统计OrgName为'成型车间'的EmployeeCode的数量。当OrgName为'成型车间'时,将对应的EmployeeCode计入统计,否则计入0。最终返回的是统计结果。
```sql
select count(case OrgName when '成型车间' then EmployeeCode else 0 end) as count_num from table_name;
```
相关问题
SELECT a.username, a.userid, a.orgname, a.orgnamehr orgnameHr, a.company company, a.idcard, sum(CASE a.hour_type WHEN 'A' THEN a.allot_hour ELSE 0 END ) aHour, sum(CASE a.hour_type WHEN 'B' THEN a.allot_hour ELSE 0 END ) bHour, sum(CASE a.hour_type WHEN 'C' THEN a.allot_hour ELSE 0 END ) cHour, sum(CASE a.hour_type WHEN 'D' THEN a.allot_hour ELSE 0 END ) dHour, sum(CASE a.hour_type WHEN 'E' THEN a.allot_hour ELSE 0 END ) eHour, sum(CASE a.hour_type WHEN 'F' THEN a.allot_hour ELSE 0 END ) fHour, sum(CASE WHEN a.hour_type IN ('A','B','C','D','E','F') THEN a.allot_hour ELSE 0 END ) countHour, CASE yearMonth WHEN CONVERT(varchar(10), d.break_sure_date, 23) >= CONVERT(varchar(10),'2023-06-06', 23) and CONVERT(varchar(10), d.break_sure_date, 23) < CONVERT(varchar(10),'2023-07-06', 23) THEN '1' ELSE '2' END FROM ems_hour_allot a
这是一个SQL查询语句,用于从`ems_hour_allot`表中检索数据。查询结果将包括以下列:`username`、`userid`、`orgname`、`orgnameHr`、`company`、`idcard`、`aHour`、`bHour`、`cHour`、`dHour`、`eHour`、`fHour`、`countHour`和`yearMonth`。
该查询使用了多个聚合函数和条件语句。对于每个用户,它计算了不同类型的小时数的总和,并将其存储在相应的列中。最后,它根据给定条件对`yearMonth`进行分类,并返回结果。
请注意,查询中的日期条件是固定的,如果需要根据特定日期进行查询,请相应地修改条件。
SELECT t1.org_id AS sonOrgId, t1.orgName AS sonOrgName, t1.id AS routeBasesectionId, t1.`name` AS routeBasesectionName, t1.nature, zw.billCode AS diseaseTypeSn, COUNT( t3.id ) AS num, ( CASE WHEN sum( CASE WHEN zw.`status` = '2' THEN zw.workNum END ) IS NOT NULL THEN sum( CASE WHEN zw.`status` = '2' THEN zw.workNum END ) WHEN sum( CASE WHEN zw.`status` = '1' THEN zw.workNum END ) IS NOT NULL THEN sum( CASE WHEN zw.`status` = '1' THEN zw.workNum END ) ELSE sum( CASE WHEN zw.`status` = '0' THEN zw.workNum END ) END ) AS totalAmount FROM mat_zx_section t3 JOIN base_bridge bb ON bb.id = t3.qshMainId LEFT JOIN mat_zx_workload zw ON zw.mainId = t3.id LEFT JOIN base_e_route_basesection t1 ON t3.baseRoute = t1.id LEFT JOIN main_construct t4 ON t3.constructId = t4.id -- 施工申请 LEFT JOIN main_construct_check t5 ON t5.id = t3.acceptanceId -- 施工申请验收 WHERE t5.process_status = '100' GROUP BY zw.billCode, t1.id, t1.nature, t1.org_id ORDER BY t1.org_id, t1.id, zw.billCode UNION ALL SELECT son_org_id AS sonOrgId, son_org_name AS sonOrgName, route_id AS routeBasesectionId, route_name AS routeBasesectionName, route_type AS nature, disease_type_sn AS diseaseTypeSn, num AS num, total_amount AS totalAmount FROM base_history_repair_statistics;这条sql语句执行失败
这个 SQL 语句可能会因为分号(;)导致执行失败。请尝试将分号(;)删除,然后再次执行该 SQL 语句。如下所示:
```
SELECT t1.org_id AS sonOrgId, t1.orgName AS sonOrgName, t1.id AS routeBasesectionId, t1.`name` AS routeBasesectionName, t1.nature, zw.billCode AS diseaseTypeSn, COUNT( t3.id ) AS num, ( CASE WHEN sum( CASE WHEN zw.`status` = '2' THEN zw.workNum END ) IS NOT NULL THEN sum( CASE WHEN zw.`status` = '2' THEN zw.workNum END ) WHEN sum( CASE WHEN zw.`status` = '1' THEN zw.workNum END ) IS NOT NULL THEN sum( CASE WHEN zw.`status` = '1' THEN zw.workNum END ) ELSE sum( CASE WHEN zw.`status` = '0' THEN zw.workNum END ) END ) AS totalAmount FROM mat_zx_section t3 JOIN base_bridge bb ON bb.id = t3.qshMainId LEFT JOIN mat_zx_workload zw ON zw.mainId = t3.id LEFT JOIN base_e_route_basesection t1 ON t3.baseRoute = t1.id LEFT JOIN main_construct t4 ON t3.constructId = t4.id -- 施工申请 LEFT JOIN main_construct_check t5 ON t5.id = t3.acceptanceId -- 施工申请验收 WHERE t5.process_status = '100' GROUP BY zw.billCode, t1.id, t1.nature, t1.org_id ORDER BY t1.org_id, t1.id, zw.billCode UNION ALL SELECT son_org_id AS sonOrgId, son_org_name AS sonOrgName, route_id AS routeBasesectionId, route_name AS routeBasesectionName, route_type AS nature, disease_type_sn AS diseaseTypeSn, num AS num, total_amount AS totalAmount FROM base_history_repair_statistics
```
阅读全文