partition clause : PARTITION « Analytical Functions « Oracle PL / SQL






partition clause

  
create table employee(
         no                 integer         primary key
        ,lastname               varchar2(20)    not null
        ,salary                 number(3)
        ,dept_no                 integer
);


insert into employee(no, lastname, salary,dept_no)
             values (1,'Tom', 400,1);

insert into employee(no, lastname, salary,dept_no)
             values (2,'Jack', 300,2);

insert into employee(no, lastname, salary,dept_no)
             values (3,'Lee', 200,3);

insert into employee(no, lastname, salary,dept_no)
             values (4,'Smith', 100,4);


select lastname , dept_no, salary,
       sum(salary) over (partition by dept_no) total_salary
from employee
order by dept_no, lastname;


LASTNAME                DEPT_NO     SALARY TOTAL_SALARY
-------------------- ---------- ---------- ------------
Tom                           1        400          400
Jack                          2        300          300
Lee                           3        200          200
Smith                         4        100          100


drop table employee;


   
  








Related examples in the same category

1.Partitioning with PARTITION_BY
2.Use partitioning in the OVER clause of the aggregate-analytical function like this
3.PARTITION BY: divide the groups into subgroups
4.Count(*) over partition
5.Dense_rank over partition by
6.rank and dense_rank over partition
7.count(*) over partition by, order by and range unbounded preceding
8.dense_rank() over partition by, order by
9.Top with partition
10.Partition Window
11.PARTITION BY (JOB title) and right outer join
12.SPREADSHEET PARTITION BY
13.sum salary over PARTITION BY