[英]How to sum where there's a condition from with different column
這是桌子
IP | PID | 老化 |
---|---|---|
192.168.01 | 6891 | 3個 |
192.168.01 | 6892 | 2個 |
192.168.01 | 6893 | 1個 |
192.168.01 | 6891 | 5個 |
如何僅對具有相同 IP 和 PID 的行求和。 (我想對僅具有相同 IP 和 PID 的老化列求和,例如參見已經加粗的表)。
我已經使用 WHERE 子句做了幾件事,但沒有我想要的結果。
謝謝。
如果我沒理解錯的話,你只需要將IP和PID進行聚合即可:
SELECT ID, PID, SUM(Aging) Aging
FROM yourTable
GROUP BY ID, PID;
在 Oracle DB 工作。
create table damith.temp_ip_list
(
IP varchar2(25),
pid number ,
aging number
);
insert into damith.temp_ip_list values ('192.168.01' , 6891 , 3 );
insert into damith.temp_ip_list values ('192.168.01' , 6892 , 2 );
insert into damith.temp_ip_list values ('192.168.01' , 6893 , 1 );
insert into damith.temp_ip_list values ('192.168.01' , 6891 , 5 );
commit;
SELECT IP, PID, sum(AGING) as sum_aging FROM damith.temp_ip_list group by IP, PID ;
**Output**
IP PID SUM_AGING
192.168.01 6891 8
192.168.01 6893 1
192.168.01 6892 2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.