sql插入语句insert into *** select * from

INSERT INTO YJ_123456_12
	(TRANUS,/*1.销户柜员码*/
	TRANDT,/*2.销户日期*/
	ACCTNO,/*3.账号*/
	ACCTNA,/*户名*/
	CIT_CUST_NO,/*客户名*/
	TRAD_ADVS_CUST_NO,/*交易对手客户号*/
	TRAD_ADVS_ACCT_NO,/*交易对手账号*/
	TRAD_ADVS_ACCT_NAME,/*交易对手名称*/
	TRAD_ADVS_ORG_NO,/*交易对手机构号*/
	TRAD_ADVS_ORG_NAME/*交易对手奇偶股名称*/)
  SELECT   A.TRANUS,/*1.销户柜员码*/
		   B.ORG_NO,
		   A.TRANDT,
		   A.ACCTNO,/*3.账号*/
		   A.ACCTNA,/*户名*/
		   C.CIT_CUST_NO,/*客户号*/
		   C.TRAD_ADVS_CUST_NO,/*交易对手客户号*/
		   C.TRAD_ADVS_ACCT_NO,/*交易对手账号*/
		   C.TRAD_ADVS_ACCT_NAME,/*交易对手名称*/
		   C.TRAD_ADVS_ORG_NO,
		   C.TRAD_ADVS_ORG_NAME
FROM ODS_KN_KDB_OCAC A /*开销户登记簿*/
INNER JOIN ODS_CM_OGST_USER B /*柜员信息*/
	ON A.TRANUS = B.TELLER_NO
INNER JOIN ODS_TD_TRAD_BASE C /*交易基本信息表*/
	ON A.ACCTNO = C.TRAD_ACCT
	AND DATEDIFF(DATE(A.TRANDT), DATE(C.TRAD_DATE)) BETWEEN 0 AND 7 /*开销户日期 TRANDT;TRAD_DATE 交易日期*/
	AND C.TRAD_ADVS_CUST_NO IN
		(SELECT TRAD_ADVS_CUST_NO
			FROM ODS_TD_TRAD_BASE
			GROUP BY TRAD_ADVS_CUST_NO
			HAVING COUNT(DISTINCT TRAD ACCT) > 4)
WHERE DATEDIFF(SYSDATE, DATE(A.TRANDT)) <= 7
	AND A.OPACTG = '2'
	AND A.TRANUS <> ''
	AND A.TRANUS IN (SELECT TRANUS
						FROM ODS_KN_KDB_OCAC
						WHERE OPACTG = '2'
						AND TRANUS <> ''
						AND DATEDIFF(SYSDATE,DATE(TRANDT)) >=7
						GROUP BY TRANUS
						HAVING COUNT(DISTINCT ACCTNO) > 4
						)

你可能感兴趣的:(oracle)