check_modified.py
1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
"""验证: 源表中是否有 updated_date != created_date 的记录(说明被修改过,且updated_date有更新)"""
import pymysql
from pymysql.cursors import DictCursor
SOURCE_CONFIG = {
'host': '192.168.5.23', 'port': 3306,
'user': 'user_jiangmy', 'password': 'VMziLJun',
'database': 'dj_smartcarlife', 'charset': 'utf8mb4',
'cursorclass': DictCursor,
}
TABLES = [
'dj_car_life_staff_daily_report_huawei',
'dj_car_life_staff_daily_report',
'dj_car_life_merchant_daily_report_huawei',
'dj_car_life_staff_info',
'dj_car_life_goods_order',
'dj_car_life_goods_sub_order',
'dj_car_life_goods_order_customer',
'dj_car_life_service_merchant',
]
conn = pymysql.connect(**SOURCE_CONFIG)
for table in TABLES:
with conn.cursor() as cur:
# 查: 有多少条 updated_date > created_date (被修改过的)
cur.execute(f"""
SELECT
COUNT(*) AS total,
SUM(CASE WHEN updated_date > created_date THEN 1 ELSE 0 END) AS modified,
SUM(CASE WHEN updated_date = created_date THEN 1 ELSE 0 END) AS unmodified,
MAX(updated_date) AS max_updated
FROM `{table}`
WHERE created_date IS NOT NULL AND updated_date IS NOT NULL
""")
row = cur.fetchone()
print(f"{table}")
print(f" total={row['total']:,} modified={row['modified']:,} unmodified={row['unmodified']:,} max_updated={row['max_updated']}")
print()
conn.close()