hive查询以查找不存在的ip地址和国家/地区

yhxst69z  于 2021-05-29  发布在  Hadoop
关注(0)|答案(3)|浏览(472)

我有一个名为“login”的配置单元表。它包含以下列:-

UserID | UserName | UserIP | UserCountry | Date

在某一天(那天的所有登录),我想找出userid,它是从一个用户从未访问过他的帐户的国家(usercountry)访问的,或者是从一个用户从未访问过他的帐户的ip(userip)。

ds97pgxw

ds97pgxw1#

Left Outer Join 将能满足您的要求 HIVE .

select t1.userid, t1.usercountry, t1.userip
from table t1
LEFT OUTER JOIN 
from table t2
ON (t1.userid=t2.userid) 
WHERE t1.date=xx and
t2.data < xx and
(t2.usercountry IS NULL or
t2.userip IS NULL);

希望这有帮助。。。

vhmi4jdf

vhmi4jdf2#

我认为最好的办法是集体条款!你说“以前从未访问过”,意思是count=1。
要查找ip地址,请仅使用一次:

select UserId, UserIP, COUNT(UserIP) FROM Login WHERE Date = yourdate GROUP BY UserIP, UserId HAVING COUNT(UserIP) = 1

要查找国家,请仅使用一次:

select UserId, UserCountry, COUNT(UserCountry) FROM Login WHERE Date = yourdate GROUP BY UserCountry, UserId HAVING COUNT(UserCountry) = 1
4urapxun

4urapxun3#

我会从一开始,除了我删除以前的国家和IP

select userid, usercountry, userip
from table
where date=xx
except 
select userid, usercountry, userip
from table 
where date<xx

相关问题