Skip to content
Advertisement

SQL select data grouped by attr1 with different criteria on attr2 and attr3

I have table with data like this in Access:

I need result grouped by attr1, count attr2 and count attr3 only if value is “Yes”:

I would appreciate any help with sql. Thank you very much in advance.

Advertisement

Answer

The expression for the third column is the challenge here.

Consider an IIf expression: IIf(m.attr3='Yes', 1, 0)

That expression will return 1 when the field contains ‘Yes’, and 0 otherwise.

So use that expression in a Sum() function in your query. This query returns what you requested from your sample data.

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