jeniferfleurant

HIVst start and end date

Aug 11th, 2016
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. USE caris_db;
  2. SET @start_date= "2014-10-01";
  3. SET @end_date="2015-09-30";
  4.  
  5. select CONCAT(city_code, '/', hospital_code) AS hospital_code , count(*) as "know_status", count(*) as "surveyed",
  6. #gender, dob ,
  7. #datediff("2014-01-01",dob) /365 as age,
  8. SUM(CASE
  9. WHEN
  10. gender = 2
  11. THEN
  12. 1
  13. ELSE 0
  14. END) AS male,
  15. SUM(CASE
  16. WHEN
  17. gender = 1
  18. THEN
  19. 1
  20. ELSE 0
  21. END) AS female,
  22. SUM(CASE
  23. WHEN
  24. datediff(@start_date,dob) /365 >=0
  25. AND datediff(@end_date,dob) /365 <1
  26. THEN
  27. 1
  28. ELSE 0
  29. END) AS under_1,
  30. SUM(CASE
  31. WHEN
  32. datediff(@start_date,dob) /365 >=1
  33. AND datediff(@end_date,dob) /365 <=4
  34. THEN
  35. 1
  36. ELSE 0
  37. END) AS btwn_1_and_4,
  38. SUM(CASE
  39. WHEN
  40. datediff(@start_date,dob) /365 >4
  41. AND datediff(@end_date,dob) /365 <=9
  42. THEN
  43. 1
  44. ELSE 0
  45. END) AS btwn_5_and_9,
  46. SUM(CASE
  47. WHEN
  48. datediff(@start_date,dob) /365 >9
  49. AND datediff(@end_date,dob) /365 <15
  50. THEN
  51. 1
  52. ELSE 0
  53. END) AS btwn_9_and_15
  54.  
  55. from tracking_infant i , patient
  56. where
  57. id_patient in (select id_patient from club_patient)
  58. and patient.id = i.id_patient
  59. and datediff(@start_date,dob) /365 <15
  60. and
  61. (id_patient in (select id_patient from testing_specimen where pcr_result = 1)
  62. or id_patient in (select id_patient from tracking_regime)
  63. or id_patient in (select id_patient from tracking_followup)
  64. or id_patient in (select id_patient from testing_result where result = 1)
  65. )
  66. group by hospital_code
Advertisement
Add Comment
Please, Sign In to add comment