SQL:将 CASE 与 AS 结合使用
我正在处理一个很长的 SQL 请求,我想在里面使用 CASE 但我不知道如何编写它。 我的请求看起来像:
SELECT (
SELECT id FROM first_table ft
INNER JOIN second_table st ON st.id = ft.id
INNER JOIN third_table tt ON tt.id = ft.id WHERE tt.second = 0 LIMIT 1
) as key
我想添加类似的内容:
CASE key WHEN 'One' THEN 'Two' END
我尝试在末尾添加此内容,但它不起作用:
SELECT (
SELECT id FROM first_table ft
INNER JOIN second_table st
ON st.id = ft.id
INNER JOIN third_table tt
ON tt.id = ft.id WHERE tt.second = 0 LIMIT 1
) as key CASE WHEN key = 'One' THEN 'Two' END
我的目标是沿其值编辑键
I'm working on a long SQL request and I want to use CASE inside but I don't know how to write it.
My request looks like :
SELECT (
SELECT id FROM first_table ft
INNER JOIN second_table st ON st.id = ft.id
INNER JOIN third_table tt ON tt.id = ft.id WHERE tt.second = 0 LIMIT 1
) as key
I want to add something like :
CASE key WHEN 'One' THEN 'Two' END
I tried to add this at the end but it didn't work :
SELECT (
SELECT id FROM first_table ft
INNER JOIN second_table st
ON st.id = ft.id
INNER JOIN third_table tt
ON tt.id = ft.id WHERE tt.second = 0 LIMIT 1
) as key CASE WHEN key = 'One' THEN 'Two' END
My goal is to edit key along its value
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做一个子查询:
You can do a subquery: