Advertisement
naimul64

Stipend related queries

Jul 1st, 2016
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 4.00 KB | None | 0 0
  1. -- Get number of data with invalid mobile number
  2. SELECT COUNT(*) AS total FROM `stipend_info_2021_AR` t
  3. WHERE NOT
  4. (
  5.   (SUBSTR(t.`mobile_number`,1,3) IN ('017','016','015','019','018','011') AND LENGTH(t.`mobile_number`) = 11)
  6.   OR
  7.   (SUBSTR(t.`mobile_number`,1,2) IN ('17','16','15','19','18','11') AND LENGTH(t.`mobile_number`) = 10)
  8. )
  9.  
  10. -- Set mobile_flag for data with invalid mobile number
  11. UPDATE `stipend_info_29June` t SET t.`mobile_flag` = 1;
  12.  
  13. UPDATE `stipend_info_29June` t SET t.`mobile_flag` = 0 WHERE
  14. (
  15.   (SUBSTR(t.`mobile_number`,1,3) IN ('017','016','015','019','018','011') AND LENGTH(t.`mobile_number`) = 11)
  16.   OR
  17.   (SUBSTR(t.`mobile_number`,1,2) IN ('17','16','15','19','18','11') AND LENGTH(t.`mobile_number`) = 10)
  18. );
  19.  
  20. -- Get number of data having valid mobile number and invalid amount
  21. SELECT COUNT(*) AS total FROM `stipend_info_29June` t
  22. WHERE
  23. (
  24.   (SUBSTR(t.`mobile_number`,1,3) IN ('017','016','015','019','018','011') AND LENGTH(t.`mobile_number`) = 11)
  25.   OR
  26.   (SUBSTR(t.`mobile_number`,1,2) IN ('17','16','15','19','18','11') AND LENGTH(t.`mobile_number`) = 10)
  27. )
  28. AND
  29. (t.`amount` > 3600 OR MOD(t.`amount`,25) != 0 OR t.amount is null or t.amount = 'Null');
  30.  
  31.  
  32. -- Update data with wrong amount set amount_flag
  33. UPDATE `stipend_info_29June` t SET t.`amount_flag` = 0
  34.  
  35. UPDATE `stipend_info_29June` t SET t.`amount_flag` = 1
  36. WHERE
  37. (
  38.   (SUBSTR(t.`mobile_number`,1,3) IN ('017','016','015','019','018','011') AND LENGTH(t.`mobile_number`) = 11)
  39.   OR
  40.   (SUBSTR(t.`mobile_number`,1,2) IN ('17','16','15','19','18','11') AND LENGTH(t.`mobile_number`) = 10)
  41. )
  42. AND
  43. (t.`amount` > 3600 OR MOD(t.`amount`,25) != 0 OR t.amount IS NULL OR t.amount = 'Null');
  44.  
  45. -- Export result
  46. SELECT
  47.   s.`token_no`,
  48.   s.`parent_name_bijoy` AS beneficiary,
  49.   s.`customer_wallet`,
  50.   GROUP_CONCAT(DISTINCT t.student_name_original SEPARATOR ',') AS Students_name,
  51.   SUM(s.`amount`) AS Amount,
  52.   GROUP_CONCAT(t.`class_name_orginal` SEPARATOR ',') AS classes,
  53.   COUNT(
  54.     DISTINCT t.`student_name_original`
  55.   ) AS total,
  56.   s.`school_name_original`
  57. FROM
  58.   stipend_info_29June s
  59.   INNER JOIN `student_29June` t
  60.     ON s.`id` = t.`stipend_info_id`
  61. WHERE s.mobile_flag=0
  62. AND s.`amount_flag` = 0
  63. AND s.amount IS NOT NULL
  64. GROUP BY s.`mobile_number`,
  65.   s.`parent_name_bijoy`
  66. ORDER BY s.`school_name_original`,s.`token_no` ASC;
  67.  
  68. -- Total amount-wise distribution of parents in schools (if one wants to know which total amounts are mostly found)
  69. SELECT ab.total_amount, COUNT(*) AS total, ab.school FROM
  70. (SELECT
  71.   SUM(s.`amount`) AS total_amount,
  72.   s.`school_name_unicode` AS school
  73. FROM
  74.   stipend_info_29June s
  75.   INNER JOIN `student_29June` t
  76.     ON s.`id` = t.`stipend_info_id`
  77. WHERE s.mobile_flag=0
  78. AND s.`amount_flag` = 0
  79. AND s.amount IS NOT NULL
  80. GROUP BY s.`mobile_number`,
  81. SUBSTR(s.`parent_name`, 1, 1)
  82. ) ab
  83. GROUP BY ab.total_amount, ab.school
  84. ORDER BY ab.school,total DESC
  85.  
  86.  
  87. -- To see how many persons are against each mobile number
  88. select ab.mobile_number, count(*) as COUNT, Group_Concat(ab.beneficiary separator ','), ab.school_name_unicode
  89. from
  90. (
  91. SELECT
  92.   s.`parent_name_unicode` AS beneficiary,
  93.   s.mobile_number,
  94.   SUM(s.`amount`) AS Amount,
  95.   s.`school_name_unicode`,
  96.    s.school_name_original
  97. FROM
  98.   `stipend_info_10JulDisb_1Jul-1` s
  99.   INNER JOIN `student_10JulDisb_1Jul-1` t
  100.     ON s.`id` = t.`stipend_info_id`
  101. WHERE s.mobile_flag=0
  102. AND s.amount IS NOT NULL
  103.  
  104. GROUP BY s.`mobile_number`,
  105.   s.`parent_name_bijoy`, s.school_name_original
  106.   HAVING Amount > 0
  107. ) ab
  108. group by ab.mobile_number
  109. order by  ab.school_name_unicode,COUNT desc;
  110.  
  111. -- an error check: which students from pre-primary gets 1200 taka
  112. SELECT
  113.     t.mobile_number,
  114.     t.amount AS stipendAmount,
  115.     s.amount AS studentAmount,
  116.     s.class_name_orginal
  117. FROM
  118.     `stipend_info_03072016` t
  119.         JOIN
  120.     `student_03072016` s ON t.id = s.stipend_info_id
  121. WHERE
  122.     (s.class_name LIKE '%cÖvK%'
  123.         OR s.class_name LIKE '%wkï%')
  124.         AND t.amount = 1200
  125. ORDER BY t.mobile_number;
  126. ------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement