Skip to content
Advertisement

SQL: Select rows that contains at least two items and one other item

I need to verify that a list of information given to me contains the information that has at least two items – engine (starts with either ‘E’ or ‘PE’) – and one another item – chief unit (starts with ‘BC’).

My initial query was this and I need help modifying it to show me the correct data.

Advertisement

Answer

You can use conditional aggregation to find the incidentnums that match the conditions:

You can modify the having clause to get the inverse — the ones that don’t match both conditions (= 0 or = 0).

I do not know what these conditions are for:

  • unit not like 'EMS%'
  • IncidentNum = '19-00001912'

Because they are not part of your question.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement