我要查询查询表

编程入门 行业动态 更新时间:2024-10-28 00:28:04
本文介绍了我要查询查询表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嗨 有这张桌子 我的表格名称是NEWS 以及以下字段:NewsId,NewsTitle,NewsDate 想要查询 通过选择 想要选择此表的3条记录 这3条记录是按日期显示的3条最新消息 我想获取表末3条记录(结束时间3条记录,而不是结束表) 请给我一个查询

解决方案

在这里:

SELECT TOP 3 NewsId,NewsTitle,NewsDate FROM NEWS ORDER BY NewsDate DESC

以下命令对结果进行排序,以便最新的在顶部:

ORDER BY NewsDate DESC

以下内容指示SELECT仅获取前3行:

SELECT TOP 3

您可以使用简单的技巧以升序获取最后3条记录.

SELECT * FROM ( SELECT TOP 3 NewsId,NewsTitle,NewsDate FROM NEWS ORDER BY 新闻日期 DESC ) AS DT 订单 BY DT.NewsDate

hi a have this table My table name is NEWS and this fields: NewsId ,NewsTitle,NewsDate a want get a query by select a want select 3 record of this table this 3 record is 3 last news by date i want get 3 record of end of table (3 record of end time,not of end table) please give me a query

解决方案

Here you go:

SELECT TOP 3 NewsId, NewsTitle, NewsDate FROM NEWS ORDER BY NewsDate DESC

The following orders the results so the newest are at the top:

ORDER BY NewsDate DESC

The following instructs the SELECT to get just the first 3 rows:

SELECT TOP 3

You can use a simple trick to get last 3 records in ascending order.

SELECT * FROM (SELECT TOP 3 NewsId, NewsTitle, NewsDate FROM NEWS ORDER BY NewsDate DESC) AS DT ORDER BY DT.NewsDate

更多推荐

我要查询查询表

本文发布于:2023-10-27 02:40:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1532063.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我要

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!