日期:2014-05-18  浏览次数:20670 次

SQL语句增加取得项目(不影响当前效率)
之前SQL语句如下写,想按照下列方式写,增加取得TMPQZCUSTOMERTBL表中的两个字段PH,SEQ,请问如何更改

SELECT *
FROM Customer
WHERE EXISTS (SELECT DISTINCT (1)
  FROM TMPQZCUSTOMERTBL
  WHERE CustomerDt.电话1 = TMPQZCUSTOMERTBL.CUSTOMER_TEL
  OR CustomerDt.电话2 = TMPQZCUSTOMERTBL.CUSTOMER_TEL
  OR CustomerDt.电话3 = TMPQZCUSTOMERTBL.CUSTOMER_TEL)



------解决方案--------------------
SQL code
SELECT Customer.*,
TMPQZCUSTOMERTBL.PH,
TMPQZCUSTOMERTBL.SEQ
FROM Customer,
  FROM TMPQZCUSTOMERTBL
  WHERE CustomerDt.电话1 = TMPQZCUSTOMERTBL.CUSTOMER_TEL
  OR CustomerDt.电话2 = TMPQZCUSTOMERTBL.CUSTOMER_TEL
  OR CustomerDt.电话3 = TMPQZCUSTOMERTBL.CUSTOMER_TEL

------解决方案--------------------
SQL code
SELECT a.*,b.PH,b.SEQ
FROM Customer a inner join(
SELECT DISTINCT CUSTOMER_TEL,PH,SEQ FROM TMPQZCUSTOMERTBL)b
on a.电话1 = b.CUSTOMER_TEL OR a.电话2 = b.CUSTOMER_TEL OR a.电话3 = b.CUSTOMER_TEL

------解决方案--------------------
SELECT a.*,b.PH,b.SEQ
FROM Customer a inner join(
SELECT DISTINCT CUSTOMER_TEL,PH,SEQ FROM TMPQZCUSTOMERTBL)b
on a.电话1 = b.CUSTOMER_TEL OR a.电话2 = b.CUSTOMER_TEL OR a.电话3 = b.CUSTOMER_TEL
------解决方案--------------------
SQL code
SELECT a.*,b.PH,b.SEQ
FROM Customer a inner join(
SELECT CUSTOMER_TEL,PH,SEQ FROM TMPQZCUSTOMERTBL GROUP BY  CUSTOMER_TEL,PH,SEQ )b
on a.电话1 = b.CUSTOMER_TEL OR a.电话2 = b.CUSTOMER_TEL OR a.电话3 = b.CUSTOMER_TEL