【概述】 场景 + 问题概述
使用PARTITION BY会报错:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 3 column 23 near "( PARTITION BY
语句:SELECT * FROM (SELECT *,ROW_NUMBER() over(PARTITION BY user_id order BY leave_end_time DESC) r FROM base_user_leave )t WHERE r = 1 AND leave_status in (0,1) and IS_DELETED = ‘0’
mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.12
Edition: Community
Git Commit Hash: 11a9254bec522c1991033a6098f6dccadc6eb7c1
Git Branch: HEAD
UTC Build Time: 2021-04-16 05:40:45
GoVersion: go1.15.6
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)
mysql>
mysql>
mysql> SELECT * FROM (SELECT *,ROW_NUMBER() over(PARTITION BY user_id order BY leave_end_time DESC) r FROM base_user_leave )t WHERE r = 1 AND leave_status in (0,1) and IS_DELETED = '0';
Empty set (0.00 sec)
Release Version: v4.0.12-1-g5d483c4a7
Edition: Community
Git Commit Hash: 5d483c4a78b62d5b20347931ea7587b0deda3f9c
Git Branch: hotfix-4.0.12-collation
UTC Build Time: 2021-04-27 02:50:31
GoVersion: go1.16.3
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
复现过程就是执行那个语句报错
SELECT
*
FROM
( SELECT *, ROW_NUMBER ( ) over ( PARTITION BY user_id ORDER BY leave_end_time DESC ) r FROM base_user_leave ) t
WHERE
r = 1
AND leave_status IN ( 0, 1 )
AND IS_DELETED = ‘0’
1064 - You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 4 column 35 near “( PARTITION BY user_id ORDER BY leave_end_time DESC ) r FROM base_user_leave ) t
WHERE
r = 1
AND leave_status IN ( 0, 1 )
AND IS_DELETED = ‘0’”
时间: 0.005s