Datasets:
metadata
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 thecolumn_listfield (i.e., the number of fields), which can be implemented usingJSON_LENGTH(column_list); equivalent method: remove brackets and quotes, then split by comma and take the lengthuser_count: Apply the same treatment to theuser_listfield, 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, notresult.sql - The local MySQL is running at localhost:3306, username
root, passwordroot123 - Use Python
pymysqlinresult.pyto execute the SQL (do not use themysqlcommand-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 executepython3 /tmp_workspace/result.pyyourself to verify that it runs successfully and produces correct data