Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Non optymalized
- select c1.cas,count(distinct c1.data) from casdat c1
- where c1.type='sent'
- group by c1.cas
- having count(distinct c1.data)>
- (select count(distinct c2.data) from casdat c2 where c2.type='rent' and c2.cas=c1.cas);
- //Bugged optymalized
- select c1.cas from
- casdat c1 join casdat c2 on c1.cas=c2.cas
- where c1.type='sent' and c2.type='rent'
- group by c1.cas
- having count(distinct c1.data)>count(distinct c2.data);
- //Fixed optymalized
- select c1.cas from
- casdat c1 left outer join casdat c2 on (c1.cas=c2.cas and c2.type='rent')
- where c1.type='sent'
- group by c1.cas
- having count(distinct c1.data)>count(distinct c2.data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement