34,576
社区成员
发帖
与我相关
我的任务
分享
select * from (select top 1 name,.. from table where type=1 order by n_date DESC,n_id DESC ) A
UNION ALL
select * from (select top 1 name,.. from table where type=2 order by n_date DESC,n_id DESC ) B
UNION ALL
select * from (select top 1 name,.. from table where type=3 order by n_date DESC,n_id DESC ) C
UNION ALL
select * from (select top 1 name,.. from table where type=4 order by n_date DESC,n_id DESC ) D
UNION ALL
select top 3 name,.. from table where type=5 order by n_date DESC,n_id DESC
select * from (select top 1 name,.. from table where type=1 order by n_date DESC,n_id DESC ) t1
UNION ALL
select * from (select top 1 name,.. from table where type=2 order by n_date DESC,n_id DESC ) t2
UNION ALL
select * from (select top 1 name,.. from table where type=3 order by n_date DESC,n_id DESC ) t3
UNION ALL
select * from (select top 1 name,.. from table where type=4 order by n_date DESC,n_id DESC ) t4
UNION ALL
select top 3 name,.. from table where type=5 order by n_date DESC,n_id DESC
UNION 会自动取出重复记录
UNION ALL 会保存所有记录
UNION 因为要去除相同的数据,所以效率会稍微低一些
select top 100 percent * from (select top 1 name,.. from table where type=1 order by n_date DESC,n_id DESC ) t1
UNION ALL
select top 100 percent * from (select top 1 name,.. from table where type=2 order by n_date DESC,n_id DESC ) t2
UNION ALL
select top 100 percent * from (select top 1 name,.. from table where type=3 order by n_date DESC,n_id DESC ) t3
UNION ALL
select top 100 percent * from (select top 1 name,.. from table where type=4 order by n_date DESC,n_id DESC ) t4
UNION ALL
select top 100 percent * from (select top 3 name,.. from table where type=5 order by n_date DESC,n_id DESC ) t5
SELECT xx FROM xx
UNION ALL
SELECT xx FROM xx
UNION ALL
SELECT xx FROMxx