gpt4 book ai didi

mysql - mysql中选择案例中的案例

转载 作者:IT老高 更新时间:2023-10-29 00:18:52 26 4
gpt4 key购买 nike

我已经厌倦了尝试连接到 MSSQL,所以我要切换到 mysql。进展缓慢。这是我目前的障碍:mssql:

create function W(m varchar(255)) returns int begin

declare @e int
set @e = (select COUNT(N) from P where N = m)

declare @t int
set @t = dbo.C(m)

return case @t
when 0 then -1
when 1 then
case @e when 0 then -1 else 1 end
when 2 then
case @e when 1 then -1 when 2 then 0 when 3 then 0 when 4 then 1 end
when 3 then
case @e when 1 then -1 when 2 then 1 end
when 4 then
case @e when 1 then -1 when 2 then 0 when 3 then 1 end
end
end

我想将其切换到 mysql。是否有有效的 mysql 方法:

select select case n when 0 then 1 when 1 then 2 end into var

?怎么样

set var = select case n when [...] end

?

最佳答案

这将指导您使用 Inline IF and CASE statements in MySQL

片段:

SELECT CASE num_heads
WHEN 0 THEN 'Zombie'
WHEN 1 THEN 'Human'
ELSE 'Alien'
END AS race
FROM user

mysql> SET @val := CASE num_heads
WHEN 0 THEN 'Zombie'
WHEN 1 THEN 'Human'
ELSE 'Alien'
END AS race;

mysql> SELECT @val;

关于mysql - mysql中选择案例中的案例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9236770/

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