gpt4 book ai didi

sql - 将两个匿名表相互连接

转载 作者:行者123 更新时间:2023-12-02 08:35:50 25 4
gpt4 key购买 nike

以下查询运行:

select foo.g from (select 'hello' as g) as foo

并且此查询也会运行:

select bla.x from (select 'world' as x) as bla

但这个不是:

select * from (select foo.g from (select 'hello' as g) as foo) join (select bla.x from (select 'world' as x) as bla)

我收到以下错误消息:

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'join'.

为什么会报错?是否有可能以某种方式连接这些表?

最佳答案

使用 As <temp_table_name> 给你的表命名并且您需要指定 两个表正在连接 ON .由于没有栏目加入ON我使用了重言式(结果总是True)假设你期望的结果是:你好世界在两列

这是重新排列的查询:

select * 
from
(
select foo.g
from
(
select 'hello' as g
) as foo
) As t1
inner join
(
select bla.x
from (select 'world' as x) as bla
) As t2 ON 1 = 1

关于sql - 将两个匿名表相互连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21674208/

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