Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def saveResultInCSV(db):
- cursor = db.cursor()
- cursor.execute("""
- SELECT
- th1.id tid1,
- CONCAT(th1.name, ',', dt1.name) thana1,
- sc1.school_name,
- sm.first_school_code schoolCode1,
- sm.second_school_code schoolCode2,
- sc2.school_name,
- th2.id tid2,
- CONCAT(th2.name, ',', dt2.name) thana2,
- same_mobile_no_count sameCnt,
- (Case when th1.id = th2.id then "TRUE" else "FALSE" END) sameThana
- FROM
- bugs.sameMobieNoCountBetweenDssheetAndDsheetSmaller sm
- INNER JOIN
- pesp_db_p23_live.school sc1 ON sm.first_school_code = sc1.school_code
- INNER JOIN
- pesp_db_p23_live.thana th1 ON sc1.thana_id = th1.id
- INNER JOIN
- pesp_db_p23_live.district dt1 ON th1.district_id = dt1.id
- INNER JOIN
- bugs.schoolRowCountDsSheet_intermediate itd1 ON itd1.school_code = sm.first_school_code
- LEFT JOIN
- bugs.mongoSchoolRowCount mng1 ON sm.first_school_code = mng1.school_code
- LEFT JOIN
- bugs.schoolRowCountReceiveddata_intermediate rdi1 ON sm.first_school_code = rdi1.school_code
- INNER JOIN
- pesp_db_p23_live.school sc2 ON sc2.school_code = sm.second_school_code
- INNER JOIN
- pesp_db_p23_live.thana th2 ON sc2.thana_id = th2.id
- INNER JOIN
- pesp_db_p23_live.district dt2 ON th2.district_id = dt2.id
- INNER JOIN
- bugs.schoolRowCountDsSheet_intermediate itd2 ON itd2.school_code = sm.second_school_code
- LEFT JOIN
- bugs.mongoSchoolRowCount mng2 ON sm.second_school_code = mng2.school_code
- LEFT JOIN
- bugs.schoolRowCountReceiveddata_intermediate rdi2 ON sm.second_school_code = rdi2.school_code
- WHERE
- 1 AND sc1.thana_id <= 999
- AND sc2.thana_id <= 999
- AND (100 * same_mobile_no_count / itd1.distinctMobCount >= 20
- OR 100 * same_mobile_no_count / itd2.distinctMobCount >=20)
- And same_mobile_no_count >=15
- """)
- rows = cursor.fetchall()
- description = cursor.description
- header = ()
- for desc in description:
- header= header+(desc[0],)
- cursor.close()
- now = datetime.datetime.now()
- fp = open('duplicateList.csv', 'w')
- myFile = csv.writer(fp)
- myFile.writerow(header)
- myFile.writerows(rows)
- fp.close()
- print "\nExported to CSV."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement