Advertisement
naimul64

UPdated Undefined dis, thana School SUmmary

Feb 18th, 2017
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 4.35 KB | None | 0 0
  1. -- creating a temporary table of school less rows
  2.  
  3. CREATE TABLE pesp_test_db_naimul.ds_raw_data_unmapped AS SELECT ds.id,
  4.     ds.amount,
  5.     ds.fill_up_date,
  6.     ds.has_cross_matching_done,
  7.     ds.insert_date,
  8.     ds.is_amount_absent,
  9.     ds.is_amount_invalid,
  10.     ds.is_beneficiary_name_absent,
  11.     ds.is_kyc_data_exist,
  12.     ds.is_mobile_absent,
  13.     ds.is_mobile_char_count_invalid,
  14.     ds.is_mobile_duplicate_different_school,
  15.     ds.is_mobile_duplicate_same_school,
  16.     ds.is_mobile_operator_invalid,
  17.     ds.is_name_matched,
  18.     ds.is_nid_matched,
  19.     ds.is_registered_by_ds,
  20.     ds.is_schoolcode_absent,
  21.     ds.is_student_count_absent,
  22.     ds.is_student_count_matched,
  23.     ds.is_valid,
  24.     ds.kyc_id,
  25.     ds.mobile_no,
  26.     ds.name,
  27.     ds.nid,
  28.     ds.no_of_student,
  29.     ds.school_code,
  30.     ds.status,
  31.     ds.ds_id_of_icr,
  32.     ds.row_no_of_icr,
  33.     ds.is_student_count_invalid FROM
  34.     bugs.`disbursement_sheet_analysed_raw_data` ds
  35.         LEFT JOIN
  36.     pesp_db_p23_live.school sc ON ds.school_code = sc.school_code
  37. WHERE
  38.     sc.id IS NULL;
  39.    
  40.    
  41.    
  42.    
  43.    
  44. -- running some improvements on amount field
  45. update pesp_test_db_naimul.ds_raw_data_unmapped
  46. set amount =
  47. case
  48. when amount = 6150 or amount = 8150 then 150
  49. when amount = 2001 or amount = 2000 or amount = 6200 then 200
  50. when amount = 6300 or amount = 8300 or amount = 7300 or amount = 3001 or amount = 3060 or amount = 3006 or amount = 3000 or amount = 3010 or amount = 3002 or amount = 9300 or amount = 3023 or amount = 3007 then 300
  51. when amount = 6450 then 450
  52. when amount = 6001 or amount = 6000 or amount = 6600 or amount = 8600 then 600
  53. when amount = 6750 then 750
  54. else amount
  55. end
  56. ;
  57.    
  58.    
  59. -- impossible amounts made zero
  60. update pesp_test_db_naimul.ds_raw_data_unmapped
  61. set amount = 0 where amount < 0 or amount > 1350;
  62.  
  63. update pesp_test_db_naimul.ds_raw_data_unmapped
  64. set no_of_student = 1 where no_of_student > 4;
  65.  
  66.  
  67.  
  68. -- insert Undetermined row in thana_summary
  69. insert into pesp_test_db_naimul.thana_summary (District_name,
  70.                                          District_id,
  71.                                          Thana_name,
  72.                                          TCode,
  73.                                          Total_school,
  74.                                          Total_Amount,
  75.                                          Total_Amount_Mobile,
  76.                                          Total_parents,
  77.                                          Beneficiary,
  78.                                          Disbursement_through_mobile_banking,
  79.                                          NoOfStd,
  80.                                          Beneficiary_NoOnStd,
  81.                                          Mobile_Beneficiary_Std)
  82.                             SELECT
  83.                                 'Undetermined' AS 'District_name',
  84.                                 0 as 'District_id',
  85.                                 'Undetermined' AS 'Thana name',
  86.                                 0 AS TCode,
  87.                                 COUNT(DISTINCT (d.`school_code`)) AS 'Total_school',
  88.                                 SUM(CASE
  89.                                     WHEN d.`amount` <= 1350 AND d.`amount` > 0 THEN d.`amount`
  90.                                 END) AS 'Total_Amount',
  91.                                 SUM(d.`amount`) AS 'Total_Amount_Mobile',
  92.                                 COUNT(d.`id`) AS 'Total_parents',
  93.                                 COUNT(CASE
  94.                                     WHEN d.`amount` <= 1350 AND d.`amount` > 0 THEN d.`id`
  95.                                 END) AS 'Beneficiary',
  96.                                 CAST(COUNT(CASE
  97.                                     WHEN d.`amount` <= 1350 AND d.`amount` > 0 THEN d.`id`
  98.                                 END)*90/100 AS UNSIGNED) AS 'Disbursement_through_mobile_banking',
  99.                                 SUM(d.`no_of_student`) AS NoOfStd,
  100.                                 SUM(CASE
  101.                                     WHEN d.`amount` <= 1350 AND d.`amount` > 0 THEN d.`no_of_student`
  102.                                 END) AS Beneficiary_NoOnStd,
  103.                                 SUM(d.`no_of_student`) AS 'Mobile_Beneficiary_Std'
  104.                             FROM
  105.                                 pesp_test_db_naimul.ds_raw_data_unmapped d
  106.                                 where 1
  107.                             GROUP BY 'Thana name';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement