我的表有这样的记录:
NAME AE BYTES_ALLOC MAXBYTES
---------------------------------------------------------
SYSTEM NO 10805575680 10805575680
SYSTEM YES 2147483648 10737418240
CTXD NO 52428800 52428800
SYSAUX YES 7228882944 10737418240
OLAP NO 104857600 104857600
OWAPUB NO 11534336 11534336
AKTAR NO 4294967296 4294967296
PORTAL NO 106954752 106954752
TBS NO 1073741824 1073741824
ODM NO 104857600 104857600
我只想在行上显示一个"名称"(唯一)值,如果yes
列中有no
和ae
值,则{ {1}}列。正如你所看到的,有两个"系统"行上的值。我想要的是将name
和bytes_alloc
值相加并将其maxbytes
值设为ae
。如下所示:
yes
答案 0 :(得分:2)
由于YES
“大于”NO
,您可以使用MAX()
:
SELECT NAME, MAX(AE) AE, SUM(BYTES_ALLOC) BYTES_ALLOC, SUM(MAXBYTES) MAXBYTES
FTOM TABLE
GROUP BY NAME,
答案 1 :(得分:1)
试试这个:
select name, ae, bytes_alloc, maxbytes from
(select name,
max (ae) over (partition by name order by name) ae,
sum(bytes_alloc) over (partition by name order by name) bytes_alloc,
sum(maxbytes) over (partition by name order by name) maxbytes,
row_number() over (partition by name order by name) rn
from tbl) s
where s.rn = 1