17,086
社区成员
发帖
与我相关
我的任务
分享
SQL> with t as(
2 select 1 col_1,'aaa' col_2,50 col_3 from dual union all
3 select 2,'bbb',100 from dual union all
4 select 3,'ccc',5000 from dual union all
5 select 120,'adsfasdf',4850 from dual union all
6 select 4,'ddd',4520 from dual union all
7 select 5,'eee',10201 from dual union all
8 select 6,'fff',980 from dual)
9 select t.*,sum(col_3) over (order by rownum rows between unbounded preceding and current row) col_4
10 from t
11 /
COL_1 COL_2 COL_3 COL_4
---------- -------- ---------- ----------
1 aaa 50 50
2 bbb 100 150
3 ccc 5000 5150
120 adsfasdf 4850 10000
4 ddd 4520 14520
5 eee 10201 24721
6 fff 980 25701
7 rows selected
SQL>
SQL> with t as(
2 select 1 col_1,'aaa' col_2,50 col_3 from dual union all
3 select 2,'bbb',100 from dual union all
4 select 3,'ccc',5000 from dual union all
5 select 120,'adsfasdf',4850 from dual union all
6 select 4,'ddd',4520 from dual union all
7 select 5,'eee',10201 from dual union all
8 select 6,'fff',980 from dual)
9 select col_1,col_2,col_3 from (
10 select t.*,sum(col_3) over (order by rownum rows between unbounded preceding and current row) col_4
11 from t)
12 where col_4=10000
13 /
COL_1 COL_2 COL_3
---------- -------- ----------
120 adsfasdf 4850
SQL> with t as(
2 select 1 col_1,'aaa' col_2,50 col_3 from dual union all
3 select 2,'bbb',100 from dual union all
4 select 3,'ccc',5800 from dual union all
5 select 4,'ddd',4520 from dual union all
6 select 5,'eee',10201 from dual union all
7 select 6,'fff',980 from dual)
8 select col_1,col_2,col_3 from (
9 select t.*,sum(col_3) over (order by rownum rows between unbounded preceding and current row) col_4
10 from t)
11 where col_4 < 10000
12 /
COL_1 COL_2 COL_3
---------- ----- ----------
1 aaa 50
2 bbb 100
3 ccc 5800
--获取随机行
SQL> select * from (
2 select * from emp
3 order by dbms_random.value)
4 where rownum<2
5 /
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
7902 FORD ANALYST 7566 1981-12-03 3000.00 20
SQL> /
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
7369 SMITH CLERK 7902 1980-12-17 800.00 20
SQL> /
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
7900 JAMES CLERK 7698 1981-12-03 950.00 30
SQL>