I have data:
Code Page Task
2 1 Activity
2 2 Activity
2 3 Activity Symbols
2 4 Activity Symbols
2 5 Activity Symbols
2 12 Activity
2 12 Act开发者_JS百科ivity Symbols
2 999 Consider
2 999 Constituents
2 999 Material
2 999 Material Hazards
316 999 Constituents
356 999 Constituents
398 999 Constituents
604 70 Activity Symbols
604 999 Constituents
I want to group by Code
and for each check if any of the records in that group contain a Page
of '999', if so return 'True'. Is there an aggregate function that will do this? Or perhaps there is a better way to structure a query like this?
select code,
max(case when page = '999' then 1 else 0 end) as has999
from table
group by code
精彩评论