在查询数据库前15条记录时遇到难题

ih636 2009-10-19 05:58:02
我想要多表查询数据库的内容,按时间倒排序并且只显示前15条记录
写了如下代码(其中dzzd kdzn yxcl 为表名):
select top 15 * from
(
select * from dzzd
union all
select * from kdzn
union all
select * from yxcl
)
as a
order by time desc

可是数据库有:
2009.15.19 的记录2条
2009.15.18 的记录2条
2009.15.17 的记录100条

结果在我显示的时候显示了:
2009.15.19 的记录2条
2009.15.18 的记录2条
2009.15.17 的记录100条

而我想让它显示的是:
2009.15.19 的记录2条
2009.15.18 的记录2条
2009.15.17 的记录11条

也就是说无论从数据库中查询到了多少条记录,无论任何情况,
我只要显示前15条记录,请问该怎么做

另说一下,如下方法我都试过了,没有用:
试过方法一:
select top 15 * from
(
select * from dzzd order by time desc
union all
select * from kdzn order by time desc
union all
select * from yxcl order by time desc
)
as a
order by time desc
试过方法二:
select top 15 * from
(
select top 5 * from dzzd order by time desc
union all
select top 5 * from kdzn order by time desc
union all
select top 5 * from yxcl order by time desc
)
as a
order by time desc

哪位大侠知道该怎么做麻烦告诉我一下,谢谢!!!
...全文
46 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ih636 2009-10-19
  • 打赏
  • 举报
回复
自己解决了,呵呵
ih636 2009-10-19
  • 打赏
  • 举报
回复
楼上的朋友,那个方法我试过了,不行啊,出来的日期不全
lzp4881 2009-10-19
  • 打赏
  • 举报
回复
select top 15 * from
(
select * from dzzd
union all
select * from kdzn
union all
select * from yxcl
)
as a
order by time,id desc
liuwei_IT_love 2009-10-19
  • 打赏
  • 举报
回复
顶一下

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧