Datasets:
File size: 2,594 Bytes
e8c001c | 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 | ---
id: offline-compute_MySQL_mysql_010
name: Table Heat Field Count and Query User Count Statistics with TOP Ranking
category: offline-compute/MySQL
timeout_seconds: 1800
modality: pure-text
engine: mysql
---
## Prompt
I need you to generate a MySQL script that retrieves the current day's data from the heat table, counts the number of heat fields queried and the number of querying users per table, and lands the top 10000 rows ranked by heat in descending order.
**Business Background and Objective**: Retrieve the current day's data from the heat table, count how many fields and how many users queried each table, and land the top 10000 rows ranked by heat in descending order into the output table.
**Input Table (full name + brief description)**:
- `internal_platform_db.sql_heat_column_to_ao_mysql_010` (table heat field summary table)
(Please connect to the database and query to confirm the table structure and field semantics.)
**Filter Condition**:
- `imp_date = '20260507'`
**Derived Field Rules**:
- `column_count`: Take the JSON array length of the `column_list` field (i.e., the number of fields), which can be implemented using `JSON_LENGTH(column_list)`; equivalent method: remove brackets and quotes, then split by comma and take the length
- `user_count`: Apply the same treatment to the `user_list` field, taking the JSON array length (i.e., the number of users)
**Sorting and Limit**:
- Sort by `heat DESC, column_count DESC, user_count DESC`
- Take the first 10000 rows
**Output Requirements**:
- Target table: `internal_platform_db.sql_heat_column_to_ao_top_mysql_010`
- Output field order: `imp_date` (VARCHAR), `databasename` (VARCHAR), `tablename` (VARCHAR), `column_list` (VARCHAR), `user_list` (VARCHAR), `heat` (VARCHAR), `column_count` (VARCHAR), `user_count` (VARCHAR)
- No deduplication or aggregation
- If the target table does not exist, first create it using standard MySQL InnoDB format, then write the data
- Use standard MySQL syntax; do not use Hive/Spark SQL dialects
**Environment and Execution Notes**:
- Your final output must be written to the file `/tmp_workspace/result.py`, not `result.sql`
- The local MySQL is running at localhost:3306, username `root`, password `root123`
- Use Python `pymysql` in `result.py` to execute the SQL (do not use the `mysql` command-line tool)
- The script must include complete table creation (if the target table does not exist) and data writing logic
- After writing `result.py`, you must execute `python3 /tmp_workspace/result.py` yourself to verify that it runs successfully and produces correct data
|