SQL如何在同一个字段不同类型进行条件查询统计总数
如 A 字段里面包含 1 2 3三种类型的数据,但是三种类型的数据可能是不同的人录入的,这时候要根据不同的人进行这三种类型进行数量统计
如下:
以下则是sql实现
select F_Olp_Man as '巡检员' ,F_plan_count as '巡检周期', COUNT(*) as '巡检数量',(select COUNT(F_Env_State)
from Optic_LinePat_Rec where F_Env_State='隐患' and F_Olp_Man=b.F_Olp_Man and F_plan_count=b.F_plan_count )as '隐患',
(select COUNT(F_Env_State)
from Optic_LinePat_Rec where F_Env_State='正常' and F_Olp_Man=b.F_Olp_Man and F_plan_count=b.F_plan_count )as '正常',
(select COUNT(F_Env_State)
from Optic_LinePat_Rec where F_Env_State='正常' and F_Olp_Man=b.F_Olp_Man and F_plan_count=b.F_plan_count )as '缺陷'
from Optic_LinePat_Rec b where F_well_id is not null
GROUP BY F_Olp_Man,F_plan_count
order by F_Olp_Man