oracle查询:取出每组中的第一条记录按type字段分组,code排序,取出每组中的第一条记录 方法一: select type,min(code) from group_info group by type; 注意:select 后面的列要在group by 子句中,或是用聚合函数包含,否则会有语法错误. 方法二: SELECT * FROM(SELECT z.type , z.code ,ROW_NUMBER()OVER(PARTITION BY z.type ORDER BY z.cod
Oracle 查询出来的数据取第一条 --------------------------------------------------------------------------- 转载自:http://www.itpub.net/thread-246442-1-1.html select * from (select * from <table> order by <key>) where rownum=1; select * from (select * from &l
这是先前建好的SQL数据库中的test表, sql语句: delete a from test a,(select max(id) id from test) b where a.id = b.id 这个语句使用了SQL的单表关联查询, select max(id) id from test这个SQL语句得到的是一个json对象,所以需要想办法把它取出来以使用,执行以后: 至于删除第一条信息,只要吧上面的查询条件中的max换成min即可
一.需要实现分组排序并且取组内状态优先级最高的数据 有一张这样的数据表, 需求是根据error_type分组然后取status最小的第一条数据 第一种写法: select t.* from ( select e.* from error_record e where e.status > 0 and e.error_type > 0 order by ) t group by t.error_type 这个写法无法实现我们的需求, 原因是MySQL分组查询时默认按照id从小到大的顺序排列让我们
查询中经常遇到这种查询,分组后取每组第一条.分享下一个SQL语句: --根据 x 分组后.根据 y 排序后取第一条 select * from ( select ROW_NUMBER() over(partition by x order by y desc) RowNum ,testTable.* 注:我使用MS SQL 08 R2