我有很多查询要加入一个查询,这些查询与该列重复的一个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中的某些列以外的所有列?感谢您的建议。
-- 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