0% found this document useful (0 votes)
28 views

DSW Practice SQL

The document contains SQL statements to create tables for workers, titles, and bonuses along with data being inserted. It then lists SQL queries being performed on the tables including selecting data based on conditions, aggregating, ordering, limiting, joining tables, and more.

Uploaded by

kathpaliautkarsh
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)
28 views

DSW Practice SQL

The document contains SQL statements to create tables for workers, titles, and bonuses along with data being inserted. It then lists SQL queries being performed on the tables including selecting data based on conditions, aggregating, ordering, limiting, joining tables, and more.

Uploaded by

kathpaliautkarsh
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/ 2

create table WORKER (

WORKER_id int primary key,


first_name varchar(64) not null,
last_name varchar(64),
salary int,
joining_date date,
department varchar(32)
) ;

create table title (


WORKER_REF_ID int,
worker_title varchar(64) not null,
affected_from date,
foreign key (worker_ref_id) references worker(worker_id)
);

create table Bonus (


WORKER_REF_ID int,
BONUS_DATE date,
BONUS_AMOUNT int,
foreign key (worker_ref_id) references worker(worker_id)
);

insert into worker values (001, 'Monika', 'Arora', 100000, '2014-02-20','HR');


insert into worker values (002, 'Niharika' ,'Verma' ,80000, '2014-06-11' ,'Admin'),
(003, 'Vishal' ,'Singhal' ,300000, '2014-02-20' ,'HR'),
(004, 'Amitabh' ,'Singh' ,500000, '2014-02-20' ,'Admin'),
(005, 'Vivek' ,'Bhati' ,500000, '2014-06-11' ,'Admin'),
(006, 'Vipul' ,'Diwan' ,200000, '2014-06-11' ,'Account'),
(007, 'Satish' ,'Kumar' ,75000, '2014-01-20' ,'Account'),
(008, 'Geetika', 'Chauhan', 90000, '2014-04-11','Admin');

insert into bonus values (1 ,'2016-02-20' ,5000),


(2 ,'2016-06-11' ,3000),
(3 ,'2016-02-20' ,4000),
(1 ,'2016-02-20' ,4500),
(2 ,'2016-06-11' ,3500);

#Queries

5) SELECT position('a' IN 'amitabh') from WORKER;


8) select distinct(department),length(department) from worker group by department;
11) select * from worker order by first_name asc;
12) select * from worker order by first_name asc, department desc;
13) select * from worker where first_name IN('vipul','satish');
14) select * from worker where first_name not IN('vipul','satish');
16) SELECT * from WORKER where first_name LIKE '%a%';
18) SELECT * from WORKER having length(first_name)=6 and first_name like'%h';
20) select * from worker where year(joining_date)=2014 and month(joining_date)=2;
22) select CONCAT(FIRST_NAME, ' ', LAST_NAME) As Worker_Name , salary from worker
where salary between 50000 and 100000;
23) SELECT DEPARTMENT, count(WORKER_ID) FROM WORKER GROUP BY DEPARTMENT ORDER BY
count(worker_id) DESC;

32) select salary from worker order by salary desc limit 4,1;
33) select w1.first_name , w1.salary,w1.department
from worker w1
inner join worker w2 on w1.salary=w2.salary and
w1.worker_id<>w2.worker_id;

34) select distinct(salary) from worker order by salary desc limit 1,1;

40) select distinct(salary) from worker order by salary desc limit 3;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy