我在Hive中有以下场景
Emp ID | Employee name | Emp salary
112 | Prakash | 33333
212 | Aakash | 5567
322 | Kishore | 565
3242 | hhjh | 76676
4325 | chhh | 565
422 | Ramesh | 34555
我想找出员工ID最后两位数相同的员工姓名:
例如。 Prakash和Aakash拥有员工ID相同的最后一位数字。 Kishore和Ramesh也有相同的。
输出:
112 | Prakash
212 | Aakash
322 | Kishore
422 | Ramesh
答案 0 :(得分:0)
select `Emp ID`
,`Employee name`
from (select `Emp ID`
,`Employee name`
,count(*) over (partition by `Emp ID` % 100) as cnt
from mytable
) t
where cnt > 1
;
+--------+---------------+
| emp id | employee name |
+--------+---------------+
| 212 | Aakash |
| 112 | Prakash |
| 422 | Ramesh |
| 322 | Kishore |
+--------+---------------+