json 列表数据,可以通过 sql 进行数据统计,比如:
WITH json_data AS ( SELECT '{"total": 741, "rows": [{"folderName": "aocdb", "fileName": "aocdb2_20241222_01.dmp", "fileSize": 55647989792, "fileDate": "2024-12-22", "invalidFile": "否"}, {"folderName": "aocdb", "fileName": "aocdb2_20241222_02.dmp", "fileSize": 53734613024, "fileDate": "2024-12-22", "invalidFile": "否"}], "code": 200, "msg": "查询成功"}' AS scan_record ) SELECT
min( file_date ) min_file_date,
max( file_date ) max_file_date,
count( DISTINCT FOLDER_NAME ) cnt_folder_name,
count( DISTINCT file_name ) cnt_file_name,
count( CASE WHEN file_date IS NULL THEN 1 ELSE NULL END ) cnt_disabled_file_name,
round( sum( file_size ) / 1024 / 1024 / 1024 / 1024, 2 ) sum_file_size
FROM
json_data,
JSON_TABLE (
scan_record,
"$.rows[*]" COLUMNS (
folder_Name VARCHAR ( 100 ) PATH "$.folderName",
file_Name VARCHAR ( 100 ) PATH "$.fileName",
file_Size BIGINT PATH "$.fileSize",
file_Date DATE PATH "$.fileDate",
invalid_File VARCHAR ( 10 ) PATH "$.invalidFile"
)
) AS jt;
妙啊!
不过这种方式不适合数据量很大的情况,比如列表里有30万条数据,这个时候会对服务器的内存和 CPU 造成灾难。