Advertisement
Guest User

Untitled

a guest
May 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.63 KB | None | 0 0
  1. //Non optymalized
  2. select c1.cas,count(distinct c1.data) from casdat c1
  3. where c1.type='sent'
  4. group by c1.cas
  5. having count(distinct c1.data)>
  6. (select count(distinct c2.data) from casdat c2 where c2.type='rent' and c2.cas=c1.cas);
  7.  
  8. //Bugged optymalized
  9. select c1.cas from
  10. casdat c1 join casdat c2 on c1.cas=c2.cas
  11. where c1.type='sent' and c2.type='rent'
  12. group by c1.cas
  13. having count(distinct c1.data)>count(distinct c2.data);
  14.  
  15. //Fixed optymalized
  16. select c1.cas from
  17. casdat c1 left outer join casdat c2 on (c1.cas=c2.cas and c2.type='rent')
  18. where c1.type='sent'
  19. group by c1.cas
  20. having count(distinct c1.data)>count(distinct c2.data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement