Guest User

Untitled

a guest
Apr 29th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. queryBuilder =
  2. """select PID, test_sname, test_value, units, ref_range, entry_date from labs
  3. where PID=%s and (test_sname='want' or test_sname='want2') and entry_date in
  4.  
  5. (select entry_date from labs where PID=%s and test_sname in ('want', 'want2')
  6. group by entry_date having count(*) = 2)
  7.  
  8. order by entry_date limit 10;""" % (pid, pid)
  9.  
  10. PID |test_sname |test_value |units |ref_range |entry_date
  11. 10000000 | want | 33 | U/L | 4-40 | 2008-01-01 01:01:01
  12. 10000000 | want2 | 98.34 | | | 2008-01-01 01:01:01
  13. 10000000 | NA1 | 6 | % | 4.0-6.5 | 2008-01-01 01:01:01
  14. 10000000 | NA2 | 40 | mg/dL | 70-110 | 2008-01-01 01:01:01
  15. 10000000 | NA2 | 40 | mg/dL | 70-110 | 2008-01-02 01:01:01
  16.  
  17. 10000000 | want | 33 | U/L | 4-40 | 2008-01-02 01:01:01
  18. 10000000 | want2 | 98.34 | | | 2008-01-02 01:01:01
  19. 10000000 | NA1 | 6 | % | 4.0-6.5 | 2008-01-02 01:01:01
  20. 10000000 | NA2 | 40 | mg/dL | 70-110 | 2008-01-02 01:01:01
  21. 10000000 | NA2 | 40 | mg/dL | 70-110 | 2008-01-02 01:01:01
  22.  
  23. PID |test_sname |test_value |units |ref_range |entry_date
  24. 10000000 | want | 33 | U/L | 4-40 | 2008-01-01 01:01:01
  25. 10000000 | want2 | 98.34 | | | 2008-01-01 01:01:01
  26. 10000000 | want | 33 | U/L | 4-40 | 2008-01-02 01:01:01
  27. 10000000 | want2 | 98.34 | | | 2008-01-02 01:01:01
  28.  
  29. PID |test_sname |test_value |units |ref_range |entry_date
  30. 11111111 | want | 33 | U/L | 4-40 | 2009-10-26 07:25:00
  31. 11111111 | want2 | 98.34 | | | 2009-10-26 07:25:00
  32. 11111111 | want | 189 | U/L | 135-371 | 2009-10-26 07:25:00
  33. 11111111 | NA1 | 50 | % | 4.0-6.5 | 2009-10-26 07:25:00
  34. 11111111 | NA2 | 40 | mg/dL | 70-110 | 2009-10-26 07:25:00
  35. 11111111 | NA3 | 84.55 | | | 2009-10-26 07:25:00
  36. 11111111 | NA4 | 4.5 | thou/uL | 3.9-10.7 | 2009-10-26 07:25:00
  37. 11111111 | NA5 | 14.6 | g/dL | 14.0-18.1 | 2009-10-26 07:25:00
  38. 11111111 | NA6 | 0.96 | mg/dL | 0.70-1.50 | 2009-10-26 07:25:00
  39.  
  40. 11111111 | want | 33 | U/L | 4-40 | 2009-10-30 07:25:00
  41. 11111111 | want2 | 98.34 | | | 2009-10-30 07:25:00
  42. 11111111 | want | 189 | U/L | 135-371 | 2009-10-30 07:25:00
  43. 11111111 | NA1 | 6 | % | 4.0-6.5 | 2009-10-30 07:25:00
  44. 11111111 | NA2 | 40 | mg/dL | 70-110 | 2009-10-30 07:25:00
  45. 11111111 | NA3 | 84.55 | | | 2009-10-30 07:25:00
  46. 11111111 | NA4 | 4.5 | thou/uL | 3.9-10.7 | 2009-10-30 07:25:00
  47. 11111111 | NA5 | 14.6 | g/dL | 14.0-18.1 | 2009-10-30 07:25:00
  48. 11111111 | NA6 | 0.96 | mg/dL | 0.70-1.50 | 2009-10-30 07:25:00
  49.  
  50. This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
Add Comment
Please, Sign In to add comment