Wednesday, 1 November 2017

SYNONYM

SYNONYM

SYNONYM is an alternate name for an object. It is a schema object.
Syntax
CREATE synonym E1 fro Employees;

SELECT * FROM Employees;
SELECT * FROM E1; 

Rules:

When you call the synonym name it is called the table name itself.

The insertion operation performed in the synonym means the data inserted in the table.

There are multiple number of synonym created in the single table.

The synonym name alteration is possible by using another synonyms name.

CREATE synonym E2 for E1;

Now E2 will call the E1
    E1 will call the table Employees;

DROP SYNONYM E2;-- This is the command for drop synonym

RENAME E1 to E5;-- You can change the synonym name it means rename the old synonym name.

When table is dropped means synonym does not dropped.

After drop the table the synonym is call means Error ORA-00980 Synonym translation is no longer valid.

When you drop the synonym name means synonym only dropped table does not dropped.

Without table synonym is created but its synonym call means error occur.

Two Types 

Private Synonym : You cant access the synonym for any schema.
Public Synonym  : You can access the synonym for any schema.  

A normal synonym is called private synonym whereas a public synonym is created by a keyword public.

A private synonym is accessible within your schema and a public synonym is accessible to any schema in the database.

CREATE SYNONYM system privilege is required to create a private synonym and CREATE PUBLIC SYNONYM system privilege is required to create a public synonym

DCL DATA CONTROL LANGUAGE


DCL DATA CONTROL LANGUAGE

GRANT
REVOKE

DATABASE
Its a collection of schema(users).

To Find the database user

SQL> SELECT name from v$database;

NAME                                                                
------                                                           
XE                                                                              
To Find the how many users in the database

SQL> SELECT * FROM all_users;

USERNAME                          USER_ID CREATED                               
------------------------------ ---------- ---------                             
XS$NULL                        2147483638 29-MAY-14                             
SUGA                                   50 11-JAN-17                             
ANBU                                   49 09-MAR-16                             
PARTHI                                 48 09-MAR-16                             
APEX_040000                            47 29-MAY-14                             
APEX_PUBLIC_USER                       45 29-MAY-14                             
FLOWS_FILES                            44 29-MAY-14                             
HR                                     43 29-MAY-14                             
MDSYS                                  42 29-MAY-14                             
ANONYMOUS                              35 29-MAY-14                             
CTXSYS                                 32 29-MAY-14                             
APPQOSSYS                              30 29-MAY-14                             
DBSNMP                                 29 29-MAY-14                             
ORACLE_OCM                             21 29-MAY-14                             
DIP                                    14 29-MAY-14                             
OUTLN                                   9 29-MAY-14                             
SYSTEM                                  5 29-MAY-14                             
SYS                                     0 29-MAY-14                             

To Create a new user.

SQL> CREATE user KARTHI identified by admin;
User created.

To Give permission for newly created user.

SQL> GRANT CONNECT, RESOURCE TO KARTHI;
Grant succeeded.

To Change the Password in their login

SQL> ALTER USER KARTHI identified by open;
User altered.

To Give permission for access data.

SQL> GRANT SELECT ON EMPLOYEES TO KARTHI;
Grant succeeded.

To Remove the permissions for access the data.

SQL> REVOKE SELECT ON Employees FROM KARTHI;
Revoke succeeded.

To Give all Privillages like INSERT, DELETE,UPDATE

SQL> GRANT INSERT,DELETE,UPDATE ON Employees to karthi;
Grant succeeded.

To view all Privillages and who gives permission to whom.

SQL> select * from user_tab_privs;

GRANTEE   OWNER      TABLE_NAME     GRANTOR    PRIVILEGE     GRA HIE                            
--------  ---------  -------------  ---------  ------------- --- ---                            
KARTHI    HR         EMPLOYEES      HR         UPDATE        NO  NO                             
KARTHI    HR         EMPLOYEES      HR         INSERT        NO  NO                             
KARTHI    HR         EMPLOYEES      HR         DELETE        NO  NO                             

3 rows selected.

To remove all permissions.

SQL> revoke all on employees from karthi;
Revoke succeeded.

To give permission to all users.

SQL> GRANT SELECT ON EMPLOYEES TO public;
Grant succeeded.

To remove permission to all users.

SQL> revoke SELECT ON EMPLOYEES from public;
Revoke succeeded.

ROLE: Group of USER

SQL> create role r1;
Role created.

SQL> GRANT R1 to karthi,parthi,anbu;
Grant succeeded.

SQL> GRANT SELECT ON EMPLOYEES TO r1;
Grant succeeded.

SQL> revoke r1 from parthi;
Revoke succeeded.

SQL> drop role r1;
Role dropped.

To give permissions for all tables.If DBA Permission granted means the user can create an another user.

SQL> grant dba to karthi;
Grant succeeded.

To remove permissions for all tables.

SQL> revoke dba from  karthi;
Revoke succeeded.

SQL> drop user karthi;
User dropped.

Friday, 13 October 2017

SUB QUERY

Sub Query :

A query embedded with in an another query is known as subquery.

Types :

  • Single Row Sub Query 
  • Multiple Row Sub Query 
  • Scalar Sub Query 
  • Inline View 
  • Correlated Sub Query 
  • Nested Sub Query 
  • Multiple Column Sub Query.

SELECT First_name, Salary FROM Employees WHERE Salary = ( SELECT MAX(Salary) From Employees); 

In the Query Sub Query(Inner Query ) is executed first. 

SELECT First_name, Salary FROM Employees WHERE Salary = ( SELECT MAX(Salary) FROM Employees) or Salary = (SELECT MIN(Salary) FROM Employees);

More than one query is possible. 
Different table is also possible.

>ALL :  Greater than ALL 

Greater than the greatest Value 
Salary>All (17000,9000)
It return 17000 greater value.

>ANY : Greater than any
  
Greater than the lowest Value.
Salary>Any (17000,9000)
It return 9000 greater value. 

SINGLE ROW SUB QUERY:

Sub Query returns only one row means it is single row sub query.
Operators used in the single row sub query. <=,<,=>,>,<>

SELECT First_name, Salary FROM Employees WHERE Salary <=( SELECT salary  FROM Employees WHERE First_name= 'Neena');

SELECT First_name, Salary FROM Employees WHERE Salary <( SELECT salary  FROM Employees WHERE First_name= 'Neena');

SELECT First_name, Salary FROM Employees WHERE Salary >=( SELECT salary  FROM Employees WHERE First_name= 'Neena');

SELECT First_name, Salary FROM Employees WHERE Salary >( SELECT salary  FROM Employees WHERE First_name= 'Neena');

SELECT First_name, Salary FROM Employees WHERE Salary <>( SELECT salary  FROM Employees WHERE First_name= 'Neena');

MULTIPLE ROW SUB QUERY:

Sub query return more than one row is multiple row sub query.
Operators used IN ALL ANY

SELECT First_name, Salary FROM Employees WHERE Salary IN  ( SELECT salary  FROM Employees WHERE First_name= 'Alexander');

SELECT First_name, Salary FROM Employees WHERE Salary <ALL( SELECT salary  FROM Employees WHERE First_name= 'Alexander');

SELECT First_name, Salary FROM Employees WHERE Salary <ANY( SELECT salary  FROM Employees WHERE First_name= 'Alexander');

SELECT First_name, Salary FROM Employees WHERE Salary >ALL( SELECT salary  FROM Employees WHERE First_name= 'Alexander');

SELECT First_name, Salary FROM Employees WHERE Salary >ANY( SELECT salary  FROM Employees WHERE First_name= 'Alexander');

SCALAR SUB QUERY

To write a sub query in SELECT Clause

SELECT 
(SELECT COUNT(*) FROM Employees WHERE Department_id = 10)"Admin",
(SELECT COUNT(*) FROM Employees WHERE Department_id = 20)"Marketing",
(SELECT COUNT(*) FROM Employees WHERE Department_id = 30)"Purchase",
(SELECT COUNT(*) FROM Employees WHERE Department_id = 40)"Networking",
(SELECT COUNT(*) FROM Employees WHERE Department_id = 50)"Support",
(SELECT COUNT(*) FROM Employees WHERE Department_id IN (10,20,30,40,50))"Total"
FROM Dual; 

SELECT 1+2+(SELECT 1+3 FROM Dual) FROM Dual;

INLINE VIEW

To write the sub query in the FROM Clause is inline view 

SELECT * FROM (SELECT * FROM Employees) Departments;

SELECT * FROM (SELECT * FROM Employees)locations;

SELECT MIN(Salary) FROM (SELECT First_name,Salary FROM Employees WHERE Department_id=50);

NESTED SUB QUERY :

Sub Query is created first
Outer Query is depend from Sub Query
Sub Query value is used in Outer Query.

SELECT First_name,Salary from employees where department_id in (SELECT department_id FROM Employees);

MULTIPLE COLUMN SUB QUERY

Relational operator used IN,ALL, ANY
Multiple Column and Multiple rows.

SELECT First_name,Salary FROM Employees where (department_id,Salary) in (SELECT Department_id,MAX(SALARY) From Employees Group By department_id);

Here Where clause contains 2 columns, subquery contains 2 columns.

CORRELATED SUB QUERY:

Correlated Sub Query means both inner query and outer Query executed in mutually dependent.

EX: Who are all getting salary more than their department average salary

SELECT   e.employee_id
       , e.first_name
   , e.Department_id
   , e.salary 
FROM employees e 
WHERE salary> (Select ROUND(AVG(salary)) FROM employees WHERE department_id=e.department_id); 

EX: Who are all getting salary more than their  manager salary 

SELECT   e.employee_id
       , e.first_name
   , e.manager_id
   , e.salary 
FROM employees e 
WHERE salary> (Select salary FROM employees WHERE employee_id=e.manager_id); 

Monday, 25 September 2017

PSEUDO COLUMNS


PSEUDO COLUMNS

--Its not a column inside the table but it act as a column.

SYSDATE 
SYSTIMESTAMP
USER 
UID
ROWNUM
ROWID
NEXTVAL
CURRVAL

SYSDATE -- Its display the sytem date 

SQL> SELECT sysdate FROM DUAL;

SYSDATE
---------
25-SEP-17

SYSTIMESTAMP -- It display the timestamp date with time minutes seconds meridian.

SQL> SELECT systimestamp FROM DUAL;

SYSTIMESTAMP
------------------------------------------
25-SEP-17 02.34.13.201000 PM +05:30

USER -- It display the current user.

SQL> SELECT user FROM DUAL;

USER
------------------------------
HR

UID -- It display the user id.

SQL> SELECT uid FROM DUAL;

       UID
----------
        43

NEXTVAL & CURRVAL 

These are the sequence attributes 

CREATE SEQUENCE s1
START WITH 1
INCREMENT BY 1
MAXVALUE 10

Sequence Created

SQL> SELECT S2.NEXTVAL FROM DUAL;
   NEXTVAL
----------
         1
SQL> SELECT S2.NEXTVAL FROM DUAL;

   NEXTVAL
----------
         2
SQL> SELECT S2.CURRVAL FROM DUAL;
   CURRVAL
----------
         2
SQL> SELECT S2.NEXTVAL FROM DUAL;
   NEXTVAL
----------
         3

ROWNUM

-Its genertes only at run time and always starts with 1.
-Roll number never be stored in database.
-To give row numbers for the output result.

SQL> SELECT first_name, salary,rownum FROM Employees WHERE Department_id= 30;

FIRST_NAME               SALARY     ROWNUM
-------------------- ---------- ----------
Den                       11000          1
Alexander                  3100          2
Shelli                     2900          3
Sigal                      2800          4
Guy                        2600          5
Karen                      2500          6

ROWID

-It is a unique address generated by oracle when user inserts a new row in a table.
-It is permanently stored in a database. 
-Rowid is unique we can retrieve specific row using their rowid.
-Rowid cannot be modified;
-if you delete the row means the row id also deleted
-if you update the data means the row_id is the same for the row.
-rowid length is 18 charecters.

SQL> SELECT first_name, salary,rowid FROM Employees WHERE Department_id= 30;

FIRST_NAME               SALARY ROWID
-------------------- ---------- ------------------
Den                       11000 AAAEAbAAEAAAADNAAO
Alexander                  3100 AAAEAbAAEAAAADNAAP
Shelli                     2900 AAAEAbAAEAAAADNAAQ
Sigal                      2800 AAAEAbAAEAAAADNAAR
Guy                        2600 AAAEAbAAEAAAADNAAS
Karen                      2500 AAAEAbAAEAAAADNAAT

Sunday, 24 September 2017

SEQUENCE IN ORACLE


SEQUENCE :

-- Sequence automatically generates UNIQUE numbers.
-- It is shema object and sharable object.
-- It is mainly used for generating primary key column values.
-- NEXTVAL, CURRVAL are sequence attributes.

Syntax

CREATE SEQUENCE sequence_name
  MINVALUE value
  MAXVALUE value
  START WITH value
  INCREMENT BY value
  CACHE value;
  
CREATE SEQUENCE supplier_seq
  MINVALUE 1
  MAXVALUE 25
  START WITH 1
  INCREMENT BY 1
  CACHE 20;
  
--Here Minvalue 1 , maxvalue is 25 if you not mentioning the maxvalue its default take upto 999999999999999999999999999, started values as 1 and increment by 1 for every run.

--The first sequence number that it would use is 1 and each subsequent number would increment by 1 (ie: 2,3,4,...}. It will cache up to 20 values for performance.
  
CACHE is used to increase the performance of the sequence.
  
SQL> CREATE table customer(supplier_id number, supplier_name varchar2(10));

Table created.

SQL> CREATE SEQUENCE customer_1
  2  MINVALUE 1
  3  START WITH 1
  4  INCREMENT BY 1
  5  CACHE 20;

Sequence created.

NEXTVAL

SQL> INSERT into customer values(customer_1.nextval,'parthi');
SQL> INSERT into customer values(customer_1.nextval,'karthi');
SQL> INSERT into customer values(customer_1.nextval,'arthi');

SQL> select * from customer;

SUPPLIER_ID SUPPLIER_N
----------- ----------
          1 parthi
          2 karthi
          3 arthi

SQL> ALTER SEQUENCE customer_1
  2  maxvalue 6;

Sequence altered.

SQL> INSERT into customer values(customer_1.nextval,'vimal');
SQL> INSERT into customer values(customer_1.nextval,'kamal');
SQL> INSERT into customer values(customer_1.nextval,'siva');

SQL> INSERT into customer values(customer_1.nextval,'vicky');
INSERT into customer values(customer_1.nextval,'vicky')
                            *
ERROR at line 1:
ORA-08004: sequence CUSTOMER_1.NEXTVAL exceeds MAXVALUE and cannot be
instantiated

CURRVAL

SQL> SELECT customer_1.CURRVAL FROM customer;

   CURRVAL
----------
         6

SET OPERATORS


SET OPERATORS

UNION
UNION ALL
INTERSECT
MINUS

SQL> SELECT * FROM tab1;

       SNO SNAME
---------- ----------
         5 lathika
         6 karthika
         1 Parthi
         2 karthi
         3 kamal
         4 siva

6 rows selected.

SQL> SELECT * FROM tab2;

       SNO SNAME
---------- ----------
         1 siva
         2 ravi
         3 kavi
         4 santhosh
         5 santhosh
UNION 
-- Conditions 
Colomn and Data Type must same 
combine two tables and remove the duplicates 

SQL> SELECT sno FROM tab1 UNION SELECT sno FROM tab2;

       SNO
----------
         1
         2
         3
         4
         5
         6

6 rows selected.

UNION ALL 
--To include the duplicates 

SQL> SELECT sno FROM tab1 UNION ALL SELECT sno FROM tab2;

       SNO
----------
         5
         6
         1
         2
         3
         4
         1
         2
         3
         4
         5

11 rows selected.

INTERSECT

Its display common data from both table.

SQL> SELECT sno FROM tab1 INTERSECT SELECT sno FROM tab2;

       SNO
----------
         1
         2
         3
         4
         5

MINUS

To display the values in the first table not in second table.

SQL> SELECT sno FROM tab1 MINUS SELECT sno FROM tab2;

       SNO
----------
         6

Note:

-- SET OPERATORS used in more than 2 SELECT statement.
-- Top to bottom will be executed.
-- SET OPERATORS when used common data type will matched otherwise error.
-- Multiple number of columns are used in set operators condition is no of columns is matching otherwise its thrown a error.
-- order by is used in last SELECT statement. (if its used in first SELECT statement its wrong);

Friday, 22 September 2017

ANALYTICAL FUNCTION


ANALYTICAL FUNCTION 

RANK()
DENSE RANK()
ROW_NUMBER()
LEAD()
LAG()
ROLLUP()
CUBE()
FIRST()
LAST()
FIRST_VALUE()

SQL> CREATE Table t1(Id Number, Name Varchar2(10), Salary Number);

Table created.

SQL> INSERT into t1 values(1,'Parthi',24000);
SQL> INSERT into t1 values(2,'Karthi',20000);
SQL> INSERT into t1 values(3,'Arthi',20000);
SQL> INSERT into t1 values(4,'Surya',9000);
SQL> INSERT into t1 values(5,'Taj',8000);
SQL> INSERT into t1 values(6,'Priya',19000);
SQL> SELECT * FROM t1;

        ID NAME           SALARY                                                
---------- ---------- ----------                                                
         1 Parthi          24000                                                
         2 Karthi          20000                                                
         3 Arthi           20000                                                
         4 Surya            9000                                                
         5 Taj              8000                                                
         6 Priya           19000                                                

In the ANALYTICAL Function there are two keywords used.

OVER (ORDER BY COLUMN)
OVER (PARTITION BY COLUMN ORDER BY COLUMN)  

RANK() :  Equal rows are ranked the same rank.Next rank will be empty.    
 
SQL> SELECT Id, Name, Salary, RANK() over (order by salary desc) "RANK" from t1;

        ID NAME           SALARY RANK               
---------- ---------- ---------- ------------                  
         1 Parthi          24000        1                  
         2 Karthi          20000        2                  
         3 Arthi           20000        2                  
         6 Priya           19000        4                  
         4 Surya            9000        5                  
         5 Taj              8000        6                  

6 rows selected.

N th MAXIMUM Salary using RANK()

SELECT First_Name,Salary FROM 
( SELECT First_Name,Salary, RANK() OVER (ORDER BY Salary DESC) "RANK" from Employees ) where RANK = 5;

N th MAXIMUM Salary department wise by using RANK() 

SELECT First_Name,department_id,Salary FROM 
( SELECT First_Name,Salary,department_id, RANK() OVER (partition by department_id ORDER BY Salary DESC) "RANK" from Employees ) where RANK = 2;

DENSE_RANK() : Equal rows are ranked the same rank.Next rank will be named as the next position

SQL> SELECT Id, Name, Salary,DENSE_RANK() over (order by salary desc) from t1;

        ID NAME           SALARY DENSE_RANK()OVER(ORDERBYSALARYDESC)            
---------- ---------- ---------- -----------------------------------            
         1 Parthi          24000                                   1            
         2 Karthi          20000                                   2            
         3 Arthi           20000                                   2            
         6 Priya           19000                                   3            
         4 Surya            9000                                   4            
         5 Taj              8000                                   5            

6 rows selected.

Nth MAXIMUM Salary by Using DENSE_RANK 

SELECT First_Name,Salary FROM 
( SELECT First_Name,Salary,DENSE_RANK() OVER (ORDER BY Salary DESC) "RANK" from Employees ) where RANK = 5;

N th MAXIMUM Salary department wise by using RANK() 

SELECT First_Name,department_id,Salary FROM 
( SELECT First_Name,Salary,department_id, DENSE_RANK() OVER (partition by department_id ORDER BY Salary DESC) "RANK" from Employees ) where RANK = 2;


ROWNUM 

SQL> SELECT Id, Name, Salary,ROW_NUMBER() over (order by salary desc) from t1;

        ID NAME           SALARY ROW_NUMBER()OVER(ORDERBYSALARYDESC)            
---------- ---------- ---------- -----------------------------------            
         1 Parthi          24000                                   1            
         2 Karthi          20000                                   2            
         3 Arthi           20000                                   3            
         6 Priya           19000                                   4            
         4 Surya            9000                                   5            
         5 Taj              8000                                   6            

6 rows selected.

N th MAXIMUM Salary By Using ROWNUM

SELECT * FROM
(
SELECT Rownum rn, Salary FROM
(
SELECT DISTINCT Salary FROM Employees Order By Salary DESC)
)
WHERE rn=&n;

SELECT MIN(Salary) FROM 
(SELECT ROWNUM Rn, Salary FROM
(
SELECT DISTINCT Salary FROM Employees ORDER BY Salary DESC)
)
WHERE ROWNUM<=5; 

SELECT First_name, department_id, salary from 
(
 SELECT First_name, department_id, salary, row_number() OVER (ORDER BY salary DESC) as row_num from Employees e 
 )
 where row_num = 2;


N th MAXIMUM Salary of department wise By Using ROWNUM 

SELECT First_name, department_id, salary from 
(
 SELECT First_name, department_id, salary, row_number() OVER (PARTITION BY department_id ORDER BY salary DESC) as row_num from Employees e 
 )
 where row_num = 2;


LEAD 

SQL> SELECT Id, Name, Salary,LEAD(Salary,1,0) over (order by salary desc) from t1;

SQL> SELECT Id, Name, Salary,LEAD(Salary,2,100) over (order by salary desc) from t1;

LAG 

SQL> SELECT Id, Name, Salary,LAG(Salary,2,100) over (order by salary desc) from t1;

6 rows selected.

SQL> SELECT Id, Name, Salary,LAG(Salary,1,0) over (order by salary desc) from t1;
6 rows selected.

FIRST_VALUE

SELECT employee_id, department_id, hire_date , FIRST_VALUE(hire_date)
OVER (PARTITION BY department_id ORDER BY hire_date) DAY_GAP, hire_date- (FIRST_VALUE(hire_date)
OVER ( partition by department_id ORDER BY hire_date)"Day Count"
FROM employees
WHERE department_id IN (20, 30)
ORDER BY department_id, DAY_GAP;


EMPLOYEE_ID DEPARTMENT_ID HIRE_DATE DAY_GAP    Day Count
----------- ------------- --------- --------- ----------
        201            20 17-FEB-04 17-FEB-04          0
        202            20 17-AUG-05 17-FEB-04        547
        117            30 24-JUL-05 07-DEC-02        960
        116            30 24-DEC-05 07-DEC-02       1113
        118            30 15-NOV-06 07-DEC-02       1439
        119            30 10-AUG-07 07-DEC-02       1707
        114            30 07-DEC-02 07-DEC-02          0
        115            30 18-MAY-03 07-DEC-02        162

FIRST AND LAST

SELECT department_id,
       MIN(salary) KEEP (DENSE_RANK FIRST ORDER BY commission_pct) "Worst",
       MAX(salary) KEEP (DENSE_RANK LAST ORDER BY commission_pct) "Best"
  FROM employees
  GROUP BY department_id
  ORDER BY department_id;
  
DEPARTMENT_ID      Worst       Best
------------- ---------- ----------
           10       4400       4400
           20       6000      13000
           30       2500      11000
           40       6500       6500
           50       2100       8200
           60       4200       9000
           70      10000      10000
           80       6100      14000
           90      17000      24000
          100       6900      12008
          110       8300      12008
                    7000       7000
  
LISTAGG() 

    DEPT_ID DNAME
---------- ----------
        10 cse
        10 ece
        20 eee
        30 mech
        10 mech
        20 it
        30 it 

SELECT Dept_Id, LISTAGG(DName,',')within group (order by dname)"List" FROM Listagg1 group by dept_id;

   DEPT_ID DNAME
---------- ----------
        10 cse,ece,mech
        20 eee,it
        30 mech,it 

ROLLUP

SQL> SELECT * FROM t3;

    DEP_ID        SID     SALARY
---------- ---------- ----------
         1          1       4000
         1          2       6000
         1          3       6000
         1          4       6500
         1          5       7500
         2          1       7500
         2          2       6500
         2          3       8500
         2          4       9500
         2          5       9000

10 rows selected.

SELECT dep_id,sid,SUM(salary) 
FROM t3 GROUP BY ROLLUP(dep_id,sid) ORDER BY dep_id,sid;

    DEP_ID        SID SUM(SALARY)
---------- ---------- -----------
         1          1        4000
         1          2        6000
         1          3        6000
         1          4        6500
         1          5        7500
         1                  30000
         2          1        7500
         2          2        6500
         2          3        8500
         2          4        9500
         2          5        9000
         2                  41000
                            71000

CUBE

SQL> Select dep_id,sid,sum(salary) from t3 group by CUBE(dep_id,sid) order by dep_id,sid;

    DEP_ID        SID SUM(SALARY)
---------- ---------- -----------
         1          1        4000
         1          2        6000
         1          3        6000
         1          4        6500
         1          5        7500
         1                  30000
         2          1        7500
         2          2        6500
         2          3        8500
         2          4        9500
         2          5        9000
         2                  41000
                    1       11500
                    2       12500
                    3       14500
                    4       16000
                    5       16500

    DEP_ID        SID SUM(SALARY)
---------- ---------- -----------
                            71000