当前位置: 代码迷 >> ASP.NET >> 哪位高手帮小弟我写个6表联合查询的语句?都帮帮小弟我,现场揭分!
  详细解决方案

哪位高手帮小弟我写个6表联合查询的语句?都帮帮小弟我,现场揭分!

热度:2968   发布时间:2013-02-25 00:00:00.0
谁帮我写个6表联合查询的语句?都帮帮我,现场揭分!!
6个表(用1,2,3,4,5,6代替)中时间(fabushijian)最靠前的5条信息名(title)

谢谢,速度哦,马上揭!!!

------解决方案--------------------------------------------------------
create view view_001 as
select top 5 * from 1 order by fabushijian
union
select top 5 * from 2 order by fabushijian
union
select top 5 * from 3 order by fabushijian
union
select top 5 * from 4 order by fabushijian
union
select top 5 * from 5 order by fabushijian
union
select top 5 * from 6 order by fabushijian


select top 5 * from view_001 order by fabushijian

------解决方案--------------------------------------------------------
SELECT TITLE FROM (SELECT TOP 5 TITLE FROM 1 ORDER BY FABUSHIJIAN DESC) T
UNION ALL
SELECT TITLE FROM (SELECT TOP 5 TITLE FROM 2 ORDER BY FABUSHIJIAN DESC) T
UNION ALL
SELECT TITLE FROM (SELECT TOP 5 TITLE FROM 3 ORDER BY FABUSHIJIAN DESC) T
UNION ALL
SELECT TITLE FROM (SELECT TOP 5 TITLE FROM 4 ORDER BY FABUSHIJIAN DESC) T
UNION ALL
SELECT TITLE FROM (SELECT TOP 5 TITLE FROM 5 ORDER BY FABUSHIJIAN DESC) T
UNION ALL
SELECT TITLE FROM (SELECT TOP 5 TITLE FROM 6 ORDER BY FABUSHIJIAN DESC) T
  相关解决方案