因此,我使用了第一个代码:
with idlist as (
Select uniqueid as masterid
From table1
Union
Select uniqueid
From table2
)
Select i.masterid,
t1.*,
t2.*
From idlist as i
Left join table1 on t1.uniqueid = i.masterid
Left join table2 on t2.uniqueid = i.masterid上述代码的用途:将两个或多个具有相同id列和合并到一行的表接受。
第二个代码:
select [Id], [price], [description]
from [table1]
where name_1 % 10 = 8 -- enter name_1 manually
union all
select [Id], [price], [description]
from [table2]
where name_2 % 10 = 8上面代码的用途:检查一个特定的列,如果它以'8‘结尾,然后列出它的Id、价格、描述
我想要的:基本上将这两种代码组合在一起。我需要第二个代码在中运行,这是第一个代码的结果。我想为上面第一个查询的结果创建一个新表,但据我所知,在向其中插入数据之前,我需要创建所有的列,但是第一个查询的结果将是包含许多不同列的几个表的组合。尽管如此,我仍然希望两个查询之间的组合结果在一个新表中。
因此,如果必须将所有内容都放在单词和步骤中:在同一id下从tables>联合选择Id到一行,其中包含所有行内容> create及其结果>在新表上运行上面的第二段代码
谢谢
发布于 2020-03-08 12:15:03
您似乎需要两个表中的一组列,所以我想知道这是否满足了您的需要:
select *
from (select t1.*
from [table1] t1
where name_1 % 10 = 8
) t1 full join
(select t2.*
from [table2] t2
where name_2 % 10 = 8
) t2
on t1.id = t2.id;请注意,这使用的是full join --这是您的第一个查询所做的事情(假设id不是NULL)。
而且,在名为"name“的列上使用算术计算(%)似乎很奇怪。
https://stackoverflow.com/questions/60586232
复制相似问题