connection_table極品嵌套select查詢
app | src_port | dst_port | src_ip | dst_ip | time | L1 | L2 ----------+-----------+----------+----------+---------+-------+-----+---- HTTP | 100 | 200 | x | y | t1 | 1 | 0 HTTPS | 101 | 300 | x | y | t1 | 1 | 0 HTTP | 102 | 200 | a | b | t2 | 0 | 1 HTTP | 100 | 200 | x | y | t2 | 1 | 0 HTTP | 100 | 200 | x | y | t3 | 1 | 0 HTTP | 111 | 200 | x | y | t4 | 1 | 0
結果
app | sum(L1) | sum(L2) ----------+----------+-------- HTTP | 2 | 1 HTTPS | 0 | 1
查詢
select app_table.app,
SUM(app_table.L1),
SUM(app_table.L2)
from (
select app, L1, L2
from connection_table
group by app, src_port, dst_port, src_ip, dst_ip
) as app_table
group by app_table.app;
釷簡單Postgres的查詢上述查詢用於獲取結果。我需要一個沒有嵌套選擇的查詢?
在這裏,src_port,dst_port,src_ip和dst_ip唯一標識一個應用程序。需要統計每個應用的總L1和L2。
你真的使用所有的DBMS在這裏? (不要標記不涉及的產品。) – jarlh
使用派生表有什麼問題? –
簡單查詢只適用於我的應用程序。如果這是獲得結果的唯一方法,那就沒問題。 – Kranthi