请考虑下表:
IP Address
192.168.1.9
192.168.1.4
192.168.1.4
192.168.1.3
192.168.1.9
我想编写一个sql查询,以便获得以下数据:
IP Address Count
192.168.1.3 1
192.168.1.4 2
192.168.1.4 2
192.168.1.9 3
192.168.1.9 3
答案 0 :(得分:1)
使用dense_rank()
:
select ip_address, dense_rank() over (order by ip_address) as cnt
from t;
答案 1 :(得分:0)
SELECT ip_address,
ROW_NUMBER() OVER(PARTITION BY ip_address) AS count
FROM table1;
是id做什么