赞
踩
select name,sex,count(*) from user group by name,sex;
注意:在使用group by时,select xx中的xx不能单独出现,必须要在gruop by中出现,即:select a from b group by a;
以部门分组按照员工编号倒叙排序的方式查询出姓名,性别年龄
select row_number() over(partition by deptno order by empno desc) name,sex,age;
select rank() over(partition by grade order by number) cno,tno;
select dense_rank() over(partition by grade order by number) cno,tno;
group by 在进行分组之后不能够进行排序,而partition by可以进行排序。
SELECT
A.NAME,
A.SEX,
A.AGE
FROM
( SELECT ROW_NUMBER () OVER ( PARTITION BY 分组字段 ORDER BY 排序字段 ) RN, USER_INFO.* FROM USER_INFO ) A
WHERE
A.RN = 1
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。