2014-01-09 31 views
-1

我有桌面客户。我希望所有客户数据中有多个postal_code和city的匹配项。使他们更专注于这一领域(业务需求)来自同一城市的客户和使用mysql的邮政编码

客户:

cust_id city postal_code 
1001  ABCD  M123    
1002  ABCD  M124 
1003  ABCD  M123 
1004  BBCD  M001 
1005  BBCD  M001 
1006  BBCD  M002 

从客户表(我在那巨大的节数recors)我想得到这样

结果
cust_id city postal_code 
    1001  ABCD  M123    
    1003  ABCD  M123 
    1004  BBCD  M001 
    1005  BBCD  M001 

如何在mysql中实现这一点请帮助我。谢谢。

+3

你的标准是什么? – tyteen4a03

+1

结果的逻辑是什么? – sergio

+0

你想如何过滤数据? – user1844933

回答

0
CREATE VIEW DUPLICATED_CUST as SELECT city, postal_code from customers 
GROUP BY city, postal_code 
HAVING COUNT(*) > 1; 

SELECT cust_id, c.city as city , c.postal_code as code from customers c, DUPLICATED_CUST d 
where c.city=d.city and c.postal_code=d.postal_code 
+0

谢谢这对我来说完全是我想要的方式。 –

相关问题