如何选择除SQL 17中某些列以外的所有列

问题描述 投票:0回答:1

我有很多查询要加入一个查询,这些查询与该列重复的一个id列一起加入。

select t1.* , t2.* , t3.* , ...
from (query1) as t1 , (query2) as t2 , (query3) as t3 , ...
where t1.id1 = t2.id2 and t1.id1 = t3.id3 and ...

查询有很多列,我想选择每个查询中除某些列之外的所有列。例如:

select t1.(all columns except some columns) , t2.(all columns except some columns) , t3.* , ...
from (query1) as t1 , (query2) as t2 , (query3) as t3 , ...
where t1.id1 = t2.id2 and t1.id1 = t3.id3 and ...

如何选择除SQL 17中的某些列以外的所有列?感谢您的建议。

sql sql-server-2017
1个回答
0
投票
这只是解决方法-

-- In step 1 insert your query output to a temp table SELECT * INTO #Temp FROM ( select t1.* , t2.* , t3.* , ... from (query1) as t1 , (query2) as t2 , (query3) as t3 , ... where t1.id1 = t2.id2 and t1.id1 = t3.id3 and ... ) -- Then drop all columns from the temp table you wants to exclude -- from your final selection ALTER TABLE #Temp DROP COLUMN column_name1, column_name2 -- Finally, just select all records from temp table SELECT * FROM #Temp

© www.soinside.com 2019 - 2024. All rights reserved.