oracle开窗函数

前端之家收集整理的这篇文章主要介绍了oracle开窗函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

@H_404_1@

1.-- 使用ROW_NUMBER分页,查找第1-10条数据@H_404_1@ @H_404_1@ @H_404_1@ SELECT T.custid,T.companyname,T.address,T.city FROM@H_404_1@ (@H_404_1@ SELECT ROW_NUMBER() OVER(ORDER BY custid) AS rownum,custid,companyname,address,city FROM Sales.Customers@H_404_1@ ) AS TWHERE T.rownum BETWEEN 1 AND 10@H_404_1@

@H_404_1@

2.默认值应用

UPDATE T_ACTIVITY SET MINGROUPCOUNT =(SELECT max(id)+1 FROM T_ACTIVITY) WHERE ID=1 直接取最大值:——也可以排名第一的就是默认值 select id,CASE WHEN Id= (max(id) over()) then '默认' ELSE '非默认' END AS sdsdf from T_BRAND ORDER BY ID DESC 分组取默认值:——本质是分组排序 select t.pid,t.id,t.name,t.rk,CASE WHEN t.rk=1 then '默认' ELSE '非默认' END AS paixu from (select rank() over(partition BY pid order by id desc) rk,a.ID,a.PID,a.NAME from T_PRODUCT a) t   where t.rk<=5; where可以去掉,但是默认值不能合并,合并了代码很长。 select t.*,t.rowid,rank() over (partition by t.classid order by t.score,t.classid) from tablename t

原文链接:https://www.f2er.com/oracle/210859.html

猜你在找的Oracle相关文章