我有以下代码,它基本上连接了两个大表,另一个小的' chromoName'表然后用于排序一切的目的。我还从其中一列中提取一些数据并将其拆分为3列以允许排序过程。在一天结束时,我的表会生成一些我想删除的过多列。另外,我想将输出保存为我的数据库中的新TABLE(使用"到MYNEWTABLE"命令)。我想在所有服务专栏'之后保存我的桌子的最终版本。已被删除。
select*
--into patient_agk_p
from chromosomes --join the 'chrom' tbl to the BIG tbl for sorting purposes!
inner join
(
select split_part(s2, '-', 1)s3,*
from
(select split_part(id2, ':', 1)s1,split_part(id2, ':', 2) s2, *
from
---creating consolidate table!
(
select COALESCE(a.promoterid_agk_p_k4,b.promoterid_agk_p_k27ac)id2, *
from agk_p_K4 a full join agk_p_k27ac b
on a.promoterid_agk_p_k4=b.promoterid_agk_p_k27ac
order by id2
)t1
---finished creating consolidate table
)t2
) t3 on s1=chromosomes.chromname --done join the 'chrom' tbl to the BIG tbl for sorting purposes!
order by chronumber,cast(s3 as int) --sort it!
所以在这里的某个地方也许 - 可以删除说,3或4列,然后将所有内容保存到patient_agk_p ???
答案 0 :(得分:1)
使用*这里包括所有列,只列出你想要的列
select column1, column2, column3 -- replace with actual columns
--into patient_agk_p
from chromosomes --join the 'chrom' tbl to the BIG tbl for sorting purposes!
inner join
(
select split_part(s2, '-', 1)s3 -- ,* remove this if you have all the columns you need, or specify the ones you want.
from
(select split_part(id2, ':', 1)s1,split_part(id2, ':', 2) s2 -- ,* remove this if you have all the columns you need, or specify the ones you want.
from
---creating consolidate table!
(
select COALESCE(a.promoterid_agk_p_k4,b.promoterid_agk_p_k27ac)id2 -- ,* remove this if you have all the columns you need, or specify the ones you want.
from agk_p_K4 a full join agk_p_k27ac b
on a.promoterid_agk_p_k4=b.promoterid_agk_p_k27ac
order by id2
)t1
---finished creating consolidate table
)t2
) t3 on s1=chromosomes.chromname --done join the 'chrom' tbl to the BIG tbl for sorting purposes!
order by chronumber,cast(s3 as int) --sort it!
包含' *'在每个查询的末尾,您将返回所有正在连接的表中的每一列。这是非常糟糕的做法(特别是与SELECT INTO结合使用),因为如果将来修改任何表,查询结果将会改变,并且很难知道原因,因为这些字段没有明确列出。