我只是用top语法从表中删除了重复的值。但它返回错误代码。
查询:
DELETE top(SELECT COUNT(*)-1 FROM tests WHERE test_name='WALLET_01' AND product_id=25)FROM tests WHERE test_name='WALLET_01' And product_id=25;
错误代码:
错误代码:1064您的sql语法有错误;
在下面单独执行查询,返回int值为1:
SELECT COUNT(*)-1 FROM tests WHERE test_name='WALLET_01' AND product_id=25;
有人能帮我解释为什么我会有语法错误吗?
1条答案
按热度按时间nhhxz33t1#
无法在top中使用子查询
Top
语法表达
Is the numeric expression that specifies the number of rows to be returned. expression is implicitly converted to a float value if PERCENT is specified; otherwise, it is converted to bigint.
我们可以看到它不支持子查询TOP
仅限expression
编辑我看到你改变了dbms的用途。
mysql不支持
TOP
但你可以用LIMIT
获取限制行。如果没有
PK
在你的table上,你可以试着用dynamic SQL
决定在运行时要删除多少行。架构(mysql v5.6)
查询#1
db fiddle视图