Sql server 2008 r2 从dbo.XXXXX中选择top n,其中tradetype输入('a','b','c'))

Sql server 2008 r2 从dbo.XXXXX中选择top n,其中tradetype输入('a','b','c')),sql-server-2008-r2,distinct,Sql Server 2008 R2,Distinct,我在创建一个查询以将下面的SELECT查询组合成一个查询,而不是手动运行每个查询时遇到了一些问题。这有助于我自己更轻松、更快地创建CSV文件 select top 200 * from dbo.abacus where type = 'A' select top 200 * from dbo.abacus where type = 'B' select top 200 * from dbo.abacus where type = 'E' select top 200 * from d

我在创建一个查询以将下面的SELECT查询组合成一个查询,而不是手动运行每个查询时遇到了一些问题。这有助于我自己更轻松、更快地创建CSV文件

select top 200 * from dbo.abacus where  type =  'A'
select top 200 * from dbo.abacus where  type =  'B'
select top 200 * from dbo.abacus  where type =  'E'
select top 200 * from dbo.abacus  where type =  'F'
select top 200 * from dbo.abacus  where type =  'F'
select top 200 * from dbo.abacus  where type =  'FX'
select top 200 * from dbo.abacus  where type =  'E'
Try UNION:


这里有更多的阅读

干杯,这是不是可以用一个查询而不是所有选择的联合来完成呢。例如,如果您尝试从dbo.abacus中选择top 200*,在其中键入“A”、“B”…,甚至是top 1400,则没有任何东西可以保证您将获得200个。
select top 200 * from dbo.abacus where  type =  'A'
union
select top 200 * from dbo.abacus where  type =  'B'
union
select top 200 * from dbo.abacus  where type =  'E'
union
select top 200 * from dbo.abacus  where type =  'F'
union
select top 200 * from dbo.abacus  where type =  'F'
union
select top 200 * from dbo.abacus  where type =  'FX'
union
select top 200 * from dbo.abacus  where type =  'E'
select top 200 * from dbo.abacus where type = 'a'
union 
select top 200 * from dbo.abacus where type = 'b'