mysql中选择案例中的案例
我厌倦了尝试连接 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
?
I'm getting sick of trying to hook up to MSSQL, so I'm switching over to mysql.
It's slow progress. Here's my current stumper:
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
I'd like to switch this to mysql. Is there a valid mysql way to:
select select case n when 0 then 1 when 1 then 2 end into var
?
How about
set var = select case n when [...] end
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将指导您使用 内联 IF 和 CASE MySQL 中的语句
片段:
或
This will guide you in using Inline IF and CASE statements in MySQL
Snippet:
or
你的意思是
?
(http://dev.mysql.com/doc/refman/ 5.6/en/user-variables.html)
Do you mean
?
(http://dev.mysql.com/doc/refman/5.6/en/user-variables.html)