Custom aggregation in GROUP BY clause

Posted by Rire1979 on Stack Overflow See other posts from Stack Overflow or by Rire1979
Published on 2010-05-29T19:48:03Z Indexed on 2010/05/29 19:52 UTC
Read the original article Hit count: 394

Filed under:
|
|

If I have a table with a schema like this

table(Category, SubCategory1, SubCategory2, Status)

I would like to group by Category, SubCategory1 and aggregate the Status such that if not all Status values over the group have a certain value Status will be 0 otherwise 1.

So my result set will look like

(Category, SubCategory1, Status)

I don't want to write a function. I would like to do it inside the query.

© Stack Overflow or respective owner

Related posts about sql

Related posts about tsql