Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. select (
  2.  
  3. -- all udprns used on non-deleted prospects and customers >>>
  4. (select count(udprn) from (
  5. select udprn from prospects join addresses on addresses.id = address_id and deleted_at is null and udprn is not null
  6. union all
  7. select udprn from customers join addresses on addresses.id = address_id and deleted_at is null and udprn is not null) as tbl1)
  8.  
  9. -- minus >>>
  10. -
  11.  
  12. -- unique udprns used on non-deleted prospects and customers >>>
  13. (select count(distinct udprn) from (
  14. select udprn from prospects join addresses on addresses.id = address_id and deleted_at is null and udprn is not null
  15. union all
  16. select udprn from customers join addresses on addresses.id = address_id and deleted_at is null and udprn is not null) as tbl2)
  17.  
  18. ) as tbl3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement