0% found this document useful (0 votes)
550 views2 pages

SQL Queries For Practice

The document contains examples of SQL queries on multiple tables: 1. The queries update, select, and join data from tables containing information about employees, companies, works, managers, locations, and salaries. 2. Other queries select data from tables containing information about people, cars, accidents, licenses, and damages to find details about accidents and involved vehicles in certain years and locations. 3. Examples demonstrate updating data, aggregating counts, joining tables, filtering on conditions, and converting data types.

Uploaded by

rboy1993
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
0% found this document useful (0 votes)
550 views2 pages

SQL Queries For Practice

The document contains examples of SQL queries on multiple tables: 1. The queries update, select, and join data from tables containing information about employees, companies, works, managers, locations, and salaries. 2. Other queries select data from tables containing information about people, cars, accidents, licenses, and damages to find details about accidents and involved vehicles in certain years and locations. 3. Examples demonstrate updating data, aggregating counts, joining tables, filtering on conditions, and converting data types.

Uploaded by

rboy1993
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 2

Emp(eid,name,street,city) Works(eid,cid,salary) Manager(eid,manager_name) Company(cid,cname,city) 1.

> Modify the database so that Jack now lives in Newyork Update Emp Set city=Newyork Where name=Jack; 2.> Find all employees in the database who live in the same cities as the company for which they work Select E.* From Emp E , Works W , Company C Where E.eid=W.eid AND W.cid =C.cid AND E.city=C.city; 3.> Give all employees of ANZ Corporation , a 10% rise in the salary Update Emp Set salary=1.1*salary Where eid in(select eid from Works Where cid in(select cid from Company Where cname=ANZ Corporation)); 4.> Find the name, street and city of all employees who work for ABC and earn more than Rs. 20000 Select name,street,E.city From Emp E , Works W , Company C Where E.eid=W.eid AND W.cid =C.cid AND cname=ABC AND salary>20000; 5.> Find the name of all employees having i as the second letter in their names Select name from Emp Where name like _i%; 6.> Display the annual salary of all the Employees Select salary*12 as AnnualSal from Emp; 7.> Find all employees in the database who live in the same cities as their managers Select E.* From Emp E , Manager M , Emp EM Where E.eid=M.eid AND M.manager_name =EM.name AND E.city=EM.city;

Person(driverid, name, address) Car(license, model, year) Accident(report_no,date,location) Owns(driverid, license ) Participated(driverid,license,report_no,damage_amount) 1.> Find the total number of people who owned cars that were involved in accident in 1995 Select count(driverid) as No_Of_People From Participated Where report_no in( select report_no From Accident Where to_char(date)=%1995%); Note: to_char() function is used to convert date / number in to string Find the number of accidents in which the cars belonging to Sunil K were involved Select count(report_no) as No_Of_Accidents from participated where license in(Select license from Car Where driverid in( Select driverid from person Where name=Sunil K)); Update the damage amount for car with license no. Mum2022 in the accident report no. AR2197 to Rs. 5000 Update Partcipated Set damage_amount=5000 Where report_no=AR2197 AND license=Mum2022; Find the number of accidents that were reported in Mumbai region in the year 2004 Select count(report_no) as No_Of_Accidents from participated where report_no in(Select report_no from Accident Where location=Mumbai region);

2.>

3.>

4.>

You might also like