gpt4 book ai didi

mysql - WHERE EXISTS mysql查询错误

转载 作者:行者123 更新时间:2023-11-29 05:59:56 24 4
gpt4 key购买 nike

SET @userID := 1;
SELECT 1 AS isSmoker WHERE EXISTS (SELECT SituationID
FROM usersituation
WHERE UserID=@userID
AND SituationID=3);

SQL查询:

 SELECT 1 AS isSmoker WHERE EXISTS (SELECT SituationID 
FROM usersituation
WHERE UserID=@userID
AND SituationID=3)

MySQL said:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE EXISTS ( SELECT SituationID FROM usersituation WHERE UserID=@userID AND ' at line 1

这是我收到的错误,但我不知道为什么会这样。

SELECT SituationID FROM `usersituation` WHERE UserID=@userID AND SituationID=3

单独使用时返回一行。

注意:

The purpose of the Query is, if the subquery returns any value then return one row with the value of 1 in a custom column named isSmoker

最佳答案

SET @userID := 1;
SELECT 1 AS isSmoker from usersituation WHERE EXISTS ( SELECT SituationID FROM usersituation WHERE UserID=@userID AND SituationID=3);

你可以试试上面的代码。

在这里您忘记了 from 关键字。

关于mysql - WHERE EXISTS mysql查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45835891/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com