Mysql 用 SELECT CASE 的结果存储变量
我正在学习如何使用 SELECT CASE 但我不太明白,这是代码:
SET @vgls=1;
SET @lgls=1;
SET @st=SELECT CASE
WHEN @vgls=@lgls THEN "emp"
WHEN @vgls>@lgls THEN "loc"
WHEN @vgls<@lgls THEN "vis" END;
SELECT @st;
它给了我以下错误:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to you MySQL server version for the right syntax to use near 'SELECT CASE
WHEN @vgls=@lgls THEN "emp"
WHEN @vgls>@lgls THEN "loc"
WHEN @vg' at line 1
im learning how to use the SELECT CASE but i don't understand very well, here is the code:
SET @vgls=1;
SET @lgls=1;
SET @st=SELECT CASE
WHEN @vgls=@lgls THEN "emp"
WHEN @vgls>@lgls THEN "loc"
WHEN @vgls<@lgls THEN "vis" END;
SELECT @st;
It gives me the following error:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to you MySQL server version for the right syntax to use near 'SELECT CASE
WHEN @vgls=@lgls THEN "emp"
WHEN @vgls>@lgls THEN "loc"
WHEN @vg' at line 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用
SELECT ... INTO
< /a>而不是
set
将 SELECT 的结果分配给变量。所以应该这样做:You need to use
SELECT ... INTO
instead of
set
to assign the result of a SELECT to a variable. So this should do it: