connection_tablebenötigen einfache Postgres-Abfrage für verschachtelte Auswahlabfrage
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
Ergebnis
app | sum(L1) | sum(L2) ----------+----------+-------- HTTP | 2 | 1 HTTPS | 0 | 1
Abfrage
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;
Th Die obige Abfrage wird verwendet, um das Ergebnis zu erhalten. Ich brauche eine Abfrage ohne geschachtelte Auswahl?
Hier identifiziert src_port, dst_port, src_ip und dst_ip eindeutig eine App. Sie müssen die Gesamtanzahl L1 und L2 für jede App zählen.
Sind Sie wirklich alle diese dbms hier ist? (Markieren Sie keine Produkte, die nicht beteiligt sind.) – jarlh
Was ist falsch bei der Verwendung der abgeleiteten Tabelle? –
Einfache Abfrage passt nur in meine Anwendung. Wenn dies der einzige Weg ist, um das Ergebnis zu erhalten, ist es in Ordnung. – Kranthi