Advertisement
aonomike

202b Jasper

Dec 5th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.58 KB | None | 0 0
  1. SELECT implementing_partner, number_tested, When_tested_last_HIV, age_group, total, ROUND(((number_tested/total)*100), 0) as percentage
  2. FROM
  3.  
  4.     ( SELECT
  5.         (SELECT SUM(number_tested) number_tested FROM
  6.             (SELECT count(id) AS number_tested,
  7.             IFNULL(When_tested_last_HIV, 'Missing') AS When_tested_last_HIV, age_group, implementing_partner_id
  8.             FROM stag_client_hiv_testing
  9.             WHERE (
  10.                 (($P{IP} = NULL or $P{IP} IS NULL) and implementing_partner LIKE '%%')
  11.                 OR
  12.                 (implementing_partner =  $P{IP} )
  13.                    )
  14.             GROUP BY age_group,  CASE WHEN (($P{IP} = NULL or $P{IP} IS NULL) and implementing_partner LIKE '%%') THEN NULL ELSE implementing_partner END
  15.             ORDER BY age_group)
  16.         A WHERE A.age_group = B.age_group AND
  17.         (
  18.             (
  19.                 (($P{IP} = NULL or $P{IP} IS NULL) and implementing_partner LIKE '%%')
  20.                 OR
  21.                 (implementing_partner =  $P{IP} )
  22.             )
  23.         ))
  24.     AS total,B.implementing_partner, B.number_tested, B.When_tested_last_HIV, B.age_group FROM
  25.     (SELECT count(id) AS number_tested, IFNULL(When_tested_last_HIV, 'Missing') AS When_tested_last_HIV, age_group, implementing_partner
  26.     FROM stag_client_hiv_testing
  27.     WHERE
  28.         (
  29.             (($P{IP} = NULL or $P{IP} IS NULL) and implementing_partner LIKE '%%')
  30.             OR
  31.             (implementing_partner =  $P{IP} )
  32.         )
  33.     GROUP BY When_tested_last_HIV, age_group, CASE WHEN (($P{IP} = NULL or $P{IP} IS NULL) and implementing_partner LIKE '%%') THEN NULL ELSE implementing_partner END
  34.     ORDER BY age_group) B)
  35. C WHERE (
  36.         (($P{IP} = NULL or $P{IP} IS NULL) and implementing_partner LIKE '%%')
  37.         OR
  38.         (implementing_partner =  $P{IP} )
  39.    
  40.     )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement