gpt4 book ai didi

sql - 具有多个连接的sql中的case语句

转载 作者:行者123 更新时间:2023-11-29 12:44:24 25 4
gpt4 key购买 nike

我有 2 个表连接在一起并返回我想要的内容:

SELECT a, b, table_one.c, d, e 
from table_one INNER JOIN table_two ON table_two.c=table_one.d
WHERE table_two.c

我有第三个表 table_three,它也有 c 列。我需要一列带有标志(如 bool 值)的值是否出现在第三个表中。我一直在尝试为此做一个 case 语句和一个左连接,但我无法弄清楚语法。

我知道我可以将大小写作为 SELECT 之后的另一列,例如:

SELECT a, b, table_one.c, d, e
, case table_three.c
when table_three.other_column_in_table_three ISNULL THEN true
ELSE false
END
from table_one INNER JOIN....

但我不确定这是否完全正确,而且我不知道如何将左连接添加到该查询中。这是正确的想法吗?如果是这样,语法是如何工作的?

最佳答案

更简单的方法

select a, b, table_one.c, d, e
, table_three.other_column is not null as flag
from table_one inner join table_two on table_one.d = table_two.c
left join table_three on -- put here the relation rules between table_three
-- and the other tables

关于sql - 具有多个连接的sql中的case语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32749722/

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