如何使用“group by”(或类似的)语句聚合一些指定的行?

时间:2022-09-23 19:22:53

I have a Teradata table with the following structure

我有一个具有以下结构的Teradata表

ID  VALUE
--  -----
03  300
05  200
08  900

I need to create a view on top of this table that will group a few specified IDs together and aggregate their values.

我需要在这个表的顶部创建一个视图,该视图将把一些指定的id分组在一起并聚合它们的值。

   ID      VALUE
---------  -----
03 and 05  500
08         900

Is there any way to do this?

有什么办法吗?

1 个解决方案

#1


2  

Assuming ID is a character, otherwise you need to do some typecasts:

假设ID是一个字符,否则需要进行一些类型转换:

select
   case when id in ('03','05') then '03 and 05' else id end,
   sum(value)
from tab
group by 1

#1


2  

Assuming ID is a character, otherwise you need to do some typecasts:

假设ID是一个字符,否则需要进行一些类型转换:

select
   case when id in ('03','05') then '03 and 05' else id end,
   sum(value)
from tab
group by 1