我只想在过去7天中,至少有5个不同的客户端使用同一个IP地址时,选择该IP地址。但结果是错误的。
table_1
customer ip date
1 0.0.0.0 15.11.2019
2 0.0.0.0 11.11.2019
3 0.0.0.0 09.11.2019
4 0.0.0.0 10.11.2019
table_2
customer ip date
1 0.0.0.0 15.11.2019
6 1.2.2.2 11.11.2019
4 0.0.0.0 09.11.2019
8 0.0.0.0 10.11.2019
9 5.5.5.5 12.11.2019
结果应该是0.0.0.0, 因为客户1、2、3、4和8在过去的7天内使用了相同的IP地址。
SELECT y.ip,x.customer
from table_1 x
inner join
table_2 y
on y.ip = x.ip
WHERE x.DATE > SYSDATE - 7
group by y.ip,y.customer
Having Count(y.customer)>=5