Advertisement
aadddrr

Menguap

Feb 13th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WITH data_summary_monthly_amount_exclude AS (
  2. SELECT  A.date_year_month, A.ou_bu_id, A.ou_branch_id, A.ou_sub_bu_id, A.product_id, SUM(A.qty) AS qty, SUM(A.gl_amount) AS gl_amount
  3. FROM in_summary_monthly_amount A
  4. GROUP BY date_year_month, ou_bu_id, ou_branch_id, ou_sub_bu_id, A.product_id
  5. HAVING SUM(qty) = 0
  6. AND SUM(gl_amount) <> 0
  7. ) SELECT * FROM data_summary_monthly_amount_exclude A
  8. WHERE NOT EXISTS (
  9.     SELECT 1 FROM in_summary_monthly_zero_qty_amount B
  10.     WHERE A.date_year_month =  B.date_year_month
  11.     AND A.ou_bu_id = B.ou_bu_id
  12.     AND A.ou_branch_id = B.ou_branch_id
  13.     AND A.ou_sub_bu_id = B.ou_sub_bu_id
  14.     AND A.product_id = B.product_id
  15. )
  16. ORDER BY date_year_month, ou_bu_id, ou_branch_id, ou_sub_bu_id, product_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement