0
我有一张表,它给出了以下sql查询输入给出的内容。按分组划分的SQL百分比聚合条款
select server, count(*) from ServerNames where server is not null and server != '' and timestamp >= '2015-03-18'
and timestamp <= '2015-04-19' group by server;
Server | Count(*)
_________________
Server1 1700
Server2 1554
select server, ip_address, count(*) from serverNames where server is not null and server != '' and ip_address is not null and ip_address != '' and timestamp >= '2015-03-18'
and timestamp <= '2015-04-19' group by server, ip_address;
Server | ip_address | count(*)
______________________________________
Server1 Sample_ip_1 14
Server2 Sample_ip_2 209
Server1 Sample_ip_2 100
Server1 Sample_ip_1 50
我在编写计算组内百分比的查询时遇到困难。因此,例如在我的例子中,输出应该是。
Server | ip_address | Count(*) | percent
________________________________________________
Server1 Sample_ip_1 14 0.82% (14/1700)
Server2 Sample_ip_2 209 13.44%(209/1554)
Server1 Sample_ip_2 100 5.88%(100/1700)
Server2 Sample_ip_1 50 3.217(15/1554)
我该如何编写一个查询来做到这一点?
第二次输出的计数(*)/第一次计数(*)。 – station
加入这两个查询并计算百分比 –