我有两张桌子:
Table 1: Connections
Columns: id, ip, in_bytes, out_bytes, protocol
Table 2: Clients
Columns: id, ip, network
我想列出按流量排序的网络。
我需要一个查询,它在一个请求中执行以下步骤:
任何人都可以帮忙创建SQL查询吗?
答案 0 :(得分:1)
使用SUM进行简单连接?
SELECT a.id, a.ip, a.network, SUM(b.in_bytes + b.out_bytes) AS traffic
FROM Client a
INNER JOIN Connections b
ON a.ip = b.ip
GROUP BY a.id, a.ip, a.network
ORDER BY traffic