0% found this document useful (0 votes)
5 views1 page

CREATE TABLE Employee (

The document contains SQL commands to create and populate two Employee tables with different attributes. The first table includes employee details such as name, age, department, and salary, along with a query using window functions for ranking and salary analysis. The second table captures employee ID, city, and state information.

Uploaded by

Guruprasad p
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

CREATE TABLE Employee (

The document contains SQL commands to create and populate two Employee tables with different attributes. The first table includes employee details such as name, age, department, and salary, along with a query using window functions for ranking and salary analysis. The second table captures employee ID, city, and state information.

Uploaded by

Guruprasad p
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

CREATE TABLE Employee (

NAME VARCHAR(255),
AGE INT,
DEPARTMENT VARCHAR(255),
SALARY VARCHAR(255)
);

INSERT INTO Employee (AGE, NAME,DEPARTMENT, SALARY)


VALUES
(20, 'Ramesh', 'Finance',50000),
(25, 'Deep', 'Sales',30000),
(22, 'Suresh', 'Finance',50000),
(28, 'Ram', 'Finance',20000),
(22, 'Pradeep', 'Sales',20000);

-------WINDOWS FUNCTION

SELECT
Name,
Department,
Salary,
RANK() OVER(PARTITION BY Department ORDER BY Salary DESC) AS emp_rank,
ROW_NUMBER() OVER (PARTITION BY Department ORDER BY Salary DESC) AS emp_row_no,

DENSE_RANK() OVER(PARTITION BY Department ORDER BY Salary DESC) AS


emp_dense_rank,
max(salary) over(partition by Department ) as max_salary,
min(salary) over(partition by Department) as min_salary,
AVG(Salary) OVER( PARTITION BY Department) AS Avg_SalarY,
Salary,
lag(salary) over(partition by Department order by name asc) as previous_salary,
lag(salary,2,0) over(partition by Department order by name asc) as
previous_salary,
lead(salary) over(partition by Department order by name asc) as next_emp_salary
FROM
employee;

--------------------

CREATE TABLE Employee (


ID INT,
CITY VARCHAR(255),
STATE VARCHAR(255)
);

INSERT INTO Employee (ID, CITY, STATE)


VALUES
(1, 'DEF', 'ANDHRA'),
(2, 'ABC', 'KARNATAKA'),
(3, 'PQRS', 'TELANAGANA'),
(4, 'WXY', 'KERALA');

You might also like