www.zbgf.net > sql取排序后的第一行

sql取排序后的第一行

select * from (SELECT a.TRANS_DATE FROM a ORDER BY to_date(to_char(a.TRANS_DATE,'yyyy/MM/dd'),'yyyy/MM/dd') DESC) where rownum=1

假设排序的字段名字为field1降序, table name: tab SELECT field1, field2, field3... fieldn FROM (SELECT field1, field2, field3...fieldn, ROW_NUMBER() OVER(ORDER BY field1 DESC) AS RK ) FROM tab ) t WHERE rk = 1 00904是说列名不正确...

方法是: select * from (select * from t order by col1) where rownum= 2 and row_number() over(order by id) = 2 and row_number() over(order by id)

--SQL Server 2000 select top (5) * from ( select top 15 * from 表 order by 排序列 desc ) as a order by 排序列 desc --SQL Server 2005,2008,2008R2,2012通用方法 select * from ( select *,row_number() over (order by 排序列 desc) as ...

SELECT TOP 10 * FROM 表名 ORDER BY 排序字段

一般是语句用法不对。 如有以下数据: 现在要求按sal列,也就是工资列,取出最小的一条。sql语句如下: select t.* from(select emp.*,row_number() over (order by sal) rn from emp) twhere rn=1;结果如下:

没有看到你的数据库conn连接啊: @$conn = mysql_connect("yourHost","yourUserID","yourPassword"); $sql=mysql_query("select top 3 title from art_title join art_neirong on art_title.no=art_neirong.no order by last_update DESC;",$conn...

以ID为例排序,降序和升序的时候各取第一条即为LZ的第一和最后一条 select top 1 * from tblname order by id desc union select top 1 * from tblname order by id

按照索引 取 ,如下: READ TABLE INTO wa_itab index 1.

代码如下: select * from tbl_DPImg where ID in (select min(ID) from tbl_DPImg group by DPID)处理后结果为: 查找表中多余的重复记录,重复记录是根据单个字段(teamId)来判断 select * from team where teamId in (select teamId from tea...

网站地图

All rights reserved Powered by www.zbgf.net

copyright ©right 2010-2021。
www.zbgf.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com