Advertisement
naimul64

Stipend: Total amount wise distribution verification

Jul 1st, 2016
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.46 KB | None | 0 0
  1. -- to view the count of each total amount against (parent name, mobile)
  2. SELECT ab.total_amount AS tot, COUNT(*) AS total, ab.school FROM
  3. (SELECT
  4.   SUM(s.`amount`) AS total_amount,
  5.   s.`school_name_unicode` AS school
  6. FROM
  7.   stipend_info_10_11JulDis_2Jul_1 s
  8.   INNER JOIN `student_10_11JulDis_2Jul_1` t
  9.     ON s.`id` = t.`stipend_info_id`
  10. WHERE s.mobile_flag=0
  11. AND s.`amount_flag` = 0
  12. AND s.amount IS NOT NULL
  13. GROUP BY s.`mobile_number`,
  14.   SUBSTRING(s.parent_name_modified, 1, 1),s.school_name_original
  15. ) ab
  16. GROUP BY ab.total_amount, ab.school
  17. HAVING tot = 600 OR tot = 1200
  18. ORDER BY ab.school,total DESC
  19.  
  20.  
  21. -- getting the value of 600 total amount count and 1200 total amount count where 600 count is larger
  22.  select school_name, six, twelve, six/twelve from (
  23. SELECT  school_name,
  24.         MAX(IF(total_amount = 600, count, NULL)) six,
  25.         MAX(IF(total_amount = 1200, count, NULL)) twelve
  26. FROM
  27. (select total_amount , count(ab.total_amount) as count,  ab.school as school_name
  28. from
  29. (SELECT
  30.   SUM(s.`amount`) AS total_amount,
  31.   s.`school_name_unicode` AS school
  32. FROM
  33.   stipend_info_11 s
  34.   INNER JOIN `student_11` t
  35.     ON s.`id` = t.`stipend_info_id`
  36. WHERE 1=1
  37. and s.mobile_flag=0
  38. AND s.`amount_flag` = 0
  39. and flag = 0
  40. GROUP BY s.`mobile_number`,
  41.   s.`parent_name_modified`, s.school_name) ab
  42.   where total_amount in (600, 1200)
  43. group by
  44. ab.school, total_amount
  45. order by school_name, total_amount) a
  46. GROUP BY school_name
  47. ) b
  48. where b.six > 1.2 * b.twelve
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement