简体   繁体   中英

SQL query: check if pd is the same across customer_id

I have the following table with customer_id, facility_id, and pd

在此处输入图像描述

Please note that customer_id can have many facility_id . Also, each customer_id should have an unique pd .

Therefore, I would like to come across a query that checks that for each of the customer_id the pd is the same, taking in consideration that a customer may have many facility_id

 SELECT X.CUSTOMER_ID
 FROM YOUR_TABLE AS X
 GROUP BY X.CUSTOMER_ID
 HAVING MIN(X.PD)<>MAX(X.PD)

List of customers with different PD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM