Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- to view the count of each total amount against (parent name, mobile)
- SELECT ab.total_amount AS tot, COUNT(*) AS total, ab.school FROM
- (SELECT
- SUM(s.`amount`) AS total_amount,
- s.`school_name_unicode` AS school
- FROM
- stipend_info_10_11JulDis_2Jul_1 s
- INNER JOIN `student_10_11JulDis_2Jul_1` t
- ON s.`id` = t.`stipend_info_id`
- WHERE s.mobile_flag=0
- AND s.`amount_flag` = 0
- AND s.amount IS NOT NULL
- GROUP BY s.`mobile_number`,
- SUBSTRING(s.parent_name_modified, 1, 1),s.school_name_original
- ) ab
- GROUP BY ab.total_amount, ab.school
- HAVING tot = 600 OR tot = 1200
- ORDER BY ab.school,total DESC
- -- getting the value of 600 total amount count and 1200 total amount count where 600 count is larger
- select school_name, six, twelve, six/twelve from (
- SELECT school_name,
- MAX(IF(total_amount = 600, count, NULL)) six,
- MAX(IF(total_amount = 1200, count, NULL)) twelve
- FROM
- (select total_amount , count(ab.total_amount) as count, ab.school as school_name
- from
- (SELECT
- SUM(s.`amount`) AS total_amount,
- s.`school_name_unicode` AS school
- FROM
- stipend_info_11 s
- INNER JOIN `student_11` t
- ON s.`id` = t.`stipend_info_id`
- WHERE 1=1
- and s.mobile_flag=0
- AND s.`amount_flag` = 0
- and flag = 0
- GROUP BY s.`mobile_number`,
- s.`parent_name_modified`, s.school_name) ab
- where total_amount in (600, 1200)
- group by
- ab.school, total_amount
- order by school_name, total_amount) a
- GROUP BY school_name
- ) b
- where b.six > 1.2 * b.twelve
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement