简体   繁体   中英

Group Specific Rows within Group By

I'm looking to combine some specific values in an aggregation query after the group by clause. If I have to hard code in that these specific examples need to be grouped, that should be ok.

So after the group by, we have sales by person which I would like to get to the lower image

分组分组

You can use case :

select (case when salesperson in ('Luke', 'Bob', 'Luke/Bob') then 'Luke/Bob'
             else salesperson
        end) as salesperson,
       sum(sales)
from t
group by (case when salesperson in ('Luke', 'Bob', 'Luke/Bob') then 'Luke/Bob'
               else salesperson
          end);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM