gpt4 book ai didi

MySQL 'if exists' 错误

转载 作者:行者123 更新时间:2023-11-29 01:17:27 24 4
gpt4 key购买 nike

我的 MySQL 查询出现错误:

if not exists(select * from tb_user where user_id=1) then
select 'ok' as rul;
else
select 'not' as rul;
end if;

我的问题在哪里?

最佳答案

IF 语句只能在存储函数中使用。您可以使用 IF() 函数执行您想要的操作,如下所示:

SELECT IF(EXISTS(select * from tb_user where user_id=1), 'ok', 'not') as rul;

关于MySQL 'if exists' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13985950/

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