title: SQL WITH statement
body: <p>I have the query below. How come with the invoice_dt set between 1/1/2021 - 5/31/2021... the output display ALL date ranges. How would I set it to look for dups based on pay_cte within the date range?</p>
  <pre><code>with pay_cte( vendor_id,invoice_id, pay_amt,pay_cnt ) as (
  select vendor_id,invoice_id, pay_amt,count(*)
  from ps_voucher
  where invoice_dt between '01-Jan-2021' and '31-May-2021'
  group by vendor_id,invoice_id, pay_amt
  having count(*)&gt;1)
  select t.vendor_id, t.voucher_id,t.INVOICE_ID,t.gross_amt, t.INVOICE_DT
  from ps_voucher t
  join pay_cte p on t.vendor_id=p.vendor_id and t.invoice_id = p.invoice_id
  and t.gross_amt=p.pay_amt
  </code></pre>