Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

SQL rewrite - response (1) by learndwh

$
0
0

you can write like this

SELECT 

SEL

SOM.CUST_ACCT_KEY, 

SOM.ORD_ID,

SOM.EQUIPDESC,

SOM.SHIP_METH_DESC, 

SOM.D_DESC, 

SOM.SITE, 

SOM.VEND_NAME, 

SOM.ORD_DT, 

SOM.CANCEL_DT,

SOM.Address,

SOM.AGENT_ID, SOM.AGENT_FULL_NAME  

FROM (SEL CUST_ACCT_KEY, 

ORD_ID,

EQUIPDESC,

SHIP_METH_DESC, 

D_DESC, 

SITE, 

VEND_NAME, 

ORD_DT, 

CANCEL_DT,

ADDR_LINE1 || '' || ADDR_LINE2 ||'' || CITY || '' || STATE || '' || ZIP_CODE AS Address,

AGENT_ID, AGENT_FULL_NAME  

FROM SLS_ORD 

WHERE CANCEL_DT = '9999-11-17'

AND ORD_DT   BETWEEN  '2013-03-01' AND '2013-04-30'

AND SHIP_METH_DESC NOT IN ('DO NOT SHIP')) SOM

JOIN 

(SEL CUST_ACCT_KEY,  

ADDR_LINE1 || '' || ADDR_LINE2 ||'' || CITY || '' || STATE || '' || ZIP_CODE AS Address 

FROM

SLS_ORD

WHERE ORD_DT   BETWEEN  '2013-03-01' AND '2013-04-30'

AND SHIP_METH_DESC NOT IN ('DO NOT SHIP')

AND CANCEL_DT = '9999-11-17'

GROUP BY 1, 2

 HAVING COUNT(*) >=6

 ) SOM2

 ON SOM2.CUST_ACCT_KEY =  SOM.CUST_ACCT_KEY

 AND SOM2.Address = SOM.Address

 


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>