advertisements
_____________________________________________________________________________________________________________________
- Query to find out Cumulative Sum from the table
Syntax:
SELECT <Column 1>, <Column 2>,
(SELECT SUM(<Column which you need cumulative Sum>)
FROM <Table Name> WHERE ROWID<= A.ROWID) CUMU_SAL
Example:
SQL> SELECT EMP_NAME, SAL,
(SELECT SUM(SAL) FROM EMP WHERE ROWID<= A.ROWID) CUMU_SAL FROM EMP A;
EMP_NAME SAL CUMU_SAL
------------------------------ ---------- ----------
Rupal 5000 5000
Hero 5500 10500
Jain 4000 14500
John 6000 20500
Riju 7000 27500
Sam 6500 34000
Kiran 5500 39500
Peter 6800 46300
King 7600 53900
Roshan 5500 59400
Roshan 5500 64900
David 64900
12 rows selected.
- Query to find out duplicate records from the table.
Syntax:
select * from <Table Name> a
where 1<( select count(*)
from <Table Name>
where <Column Name1>=a. <Column Name1>
and <Column Name2>=a. <Column Name2>
….);
Example:
SQL> select * from emp a
where 1<( select count(*)
from emp
where emp_name=a.emp_name);
EMP_NAME DEPT SAL
------------------------------ ---------- ----------
Roshan 30 5500
Roshan 10 5500
_____________________________________________________________________________________________________________________
0 comments:
Post a Comment