当前位置: 代码迷 >> Sql Server >> SQL语句增加取得项目(不影响当前效率),该如何处理
  详细解决方案

SQL语句增加取得项目(不影响当前效率),该如何处理

热度:41   发布时间:2016-04-27 14:29:19.0
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.SEQFROM 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.SEQFROM Customer a inner join(SELECT DISTINCT CUSTOMER_TEL,PH,SEQ FROM TMPQZCUSTOMERTBL)bon 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.SEQFROM Customer a inner join(SELECT CUSTOMER_TEL,PH,SEQ FROM TMPQZCUSTOMERTBL GROUP BY  CUSTOMER_TEL,PH,SEQ )bon a.电话1 = b.CUSTOMER_TEL OR a.电话2 = b.CUSTOMER_TEL OR a.电话3 = b.CUSTOMER_TEL
  相关解决方案