Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. # count how many donations per test batch
  2. select tb.id as testBatch_id, sum(case when d.id is null then 0 else 1 end) as donation_count
  3. from TestBatch tb, DonationBatch db left join Donation d on d.donationBatch_id=db.id
  4. where db.testBatch_id=tb.id
  5. group by tb.id;
  6.  
  7. # find test batches with no test results
  8. select tb.id as testBatch_id, sum(case when btr.id is null then 0 else 1 end) as test_count
  9. from TestBatch tb, DonationBatch db left join Donation d on d.donationBatch_id=db.id left join BloodTestResult btr on btr.donation_id=d.id
  10. where db.testBatch_id=tb.id
  11. group by tb.id;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement