日期:2014-05-16  浏览次数:20836 次

mysql 子查询问题 求高人指教 急!!
SELECT CUST.TEL_1
,(SELECT GROUP_CONCAT(T4.CUSTOMER_ID) FROM 
(SELECT T1.CUSTOMER_ID AS CUSTOMER_ID FROM JHF_CUSTOMER T1 WHERE (T1.TEL_1=CUST.TEL_1 OR T1.FAX_1=CUST.TEL_1) AND T1.CUSTOMER_ID<>CUST.CUSTOMER_ID
  UNION SELECT T2.CUSTOMER_ID AS CUSTOMER_ID FROM JHF_PERSONAL T2 WHERE (T2.MOBILE_1=CUST.TEL_1 OR T2.TEL_2=CUST.TEL_1 OR T2.FAX_2=CUST.TEL_1 ) AND T2.CUSTOMER_ID<>CUST.CUSTOMER_ID
  UNION SELECT T3.CUSTOMER_ID AS CUSTOMER_ID FROM JHF_ARTIFICIAL T3 WHERE (T3.CHARGE_MAN_TEL=CUST.TEL_1 OR T3.CHARGE_MAN_MOBILE=CUST.TEL_1) AND T3.CUSTOMER_ID<>CUST.CUSTOMER_ID) T4
  ) AS TEL_1_SAME_ID
FROM TABLE_NAME AS CUST;

这样是不能使用CUST.TEL_1在子查询中做过滤的 有什么办法解决么,求指教。

------解决方案--------------------
SELECT CUST.TEL_1 
, (SELECT T1.CUSTOMER_ID AS CUSTOMER_ID FROM JHF_CUSTOMER T1 ,TABLE_NAME AS CUST WHERE (T1.TEL_1=CUST.TEL_1 OR T1.FAX_1=CUST.TEL_1) AND T1.CUSTOMER_ID<>CUST.CUSTOMER_ID ) a
FROM TABLE_NAME AS CUST;
能否运行