我的学生表如下:
1 HARWI HINDI 75 2 SHWETA ENGLISH 80 3 RUDRA MATHS 90 4 HARWI MATHS 60 5 MANVI GK 89 6 RUDRA HINDI 98 7 SHWETA MATHS 67 我需要这样的输出:
1 HARWI HINDI 75 MATHS 60 2 MANVI GK 89 3 RUDRA HINDI 98 MATHS 90 4 SHWETA ENGLISH 80 MATHS 67 我不想使用串联运算符 ||
Oracle中是否有标准函数可以帮助我实现此结果集?
问题来源于stack overflow
您可以使用analytical function以下方法:
select case when lag(name) over(partition by name order by marks) is null then dr end as sno, case when lag(name) over(partition by name order by marks) is null then name end as name, subject, marks from ( select t.*, dense_rank() over (order by t.name desc) as dr from students t -- dense rank is used to give numbers to the student - sno ) order by dr;
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。