[英]Compare two columns in DB2
I need help with a query DB2. 我需要有关查询DB2的帮助。
My table looks like this: 我的桌子看起来像这样:
IP_ID IP_TYPE_CDE UPDT_DT_TM
------------- ----------- --------------------------
47560147. 39 2012-11-06-04.16.21.000000
47560147. 319 2013-06-12-16.54.09.000000
47560002. 39 2012-11-06-04.16.21.000000
47560002. 319 2013-06-12-16.54.09.000000
47560003. 39 2012-11-06-04.16.21.000000
47560003. 39 2013-06-12-16.54.09.000000
I need to scan the database, catch all the IP_ID and compare it to that IP_ID had change in IP_TYPE_CDE. 我需要扫描数据库,捕获所有IP_ID并将其与IP_TYPE_CDE中已更改的IP_ID进行比较。
Ie, in this case it should return only IP_ID 47560147 and 47560002. 即,在这种情况下,它应该仅返回IP_ID 47560147和47560002。
You could group by ip_id
and filter by a having
clause that counts the distinct number of ip_type_cde
s: 您可以按
ip_id
分组, ip_id
having
计数ip_type_cde
的不同数量的ip_type_cde
子句进行过滤:
SELECT ip_id
FROM mytable
GROUP BY ip_id
HAVING COUNT (DISTINCT ip_type_cde) > 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.