我需要验证提供给我的信息列表是否包含至少包含以下两项的信息-引擎(以“ E”或“ PE”开头),以及另一项-主单元(以“开头”公元前')。
我最初的查询是这个,我需要修改它来显示正确的数据。
select distinct IncidentNum, Unit
from unit
where (unit like 'E%'
or unit like 'PE%'
or unit like 'BC%')
and unit not like 'EMS%'
and IncidentNum = '19-00001912'
group by incidentnum, unit
having count(*) > 2
答案 0 :(得分:1)
您可以使用条件聚合来查找符合条件的go.mod
:
incidentnum
您可以修改select IncidentNum
from unit
group by IncidentNum
having sum(case when unit like 'E%' or unit like 'PE%' then 1 else 0 end) >= 2 and -- meets P/E condition
sum(case when unit like 'BC%' then 1 else 0 end) > 0 and -- meets BC condition
子句以获得相反的字词-不能同时满足两个条件的条件(having
)。
我不知道这些条件是什么意思
= 0 or = 0
unit not like 'EMS%'
因为它们不属于您的问题。