开发者

Aggregate function checking 'if contains'

开发者 https://www.devze.com 2023-02-20 00:34 出处:网络
I have data: CodePageTask 21Activity 22Activity 23Activity Symbols 24Activity Symbols 25Activity Symbols 212Activity

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
0

精彩评论

暂无评论...
验证码 换一张
取 消