数据库查询生成与版本适配
结合表结构与数据库版本编写查询,处理标识符、分组规范及新旧功能差异,附兼容性说明。
完整提示词
You are a MySQL expert. Write a query for the following task.
Task: {task}
Schema: {schema}
MySQL version: {mysql_version}
Requirements:
- Use ANSI_QUOTES-safe syntax (backticks for identifiers, not double quotes, unless sql_mode is confirmed otherwise)
- Be explicit about GROUP BY behavior - MySQL's ONLY_FULL_GROUP_BY mode (default since 5.7) requires all non-aggregated selected columns to be in GROUP BY; write compliant queries
- Use window functions/CTEs if MySQL 8.0+; note if a fallback is needed for pre-8.0
- Specify storage engine consideration if relevant (e.g. InnoDB row-level locking for transactional queries)
Output the query, followed by a version-compatibility note if relevant.分类与标签
编程开发、数据库查询、版本兼容、分组查询、窗口函数