0% found this document useful (0 votes)
157 views42 pages

DBMS Record

The document contains SQL queries to retrieve data from various database tables. The queries select, filter, and order data based on column values and conditions. Aggregate functions like count, sum, and average are also used in some queries.

Uploaded by

Kathiravan v
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
157 views42 pages

DBMS Record

The document contains SQL queries to retrieve data from various database tables. The queries select, filter, and order data based on column values and conditions. Aggregate functions like count, sum, and average are also used in some queries.

Uploaded by

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

.

DBMSRECORD

.1.Query the NAME and COUNTRYCODE of CITY Table where ID is greater than
3000
Select NAME,COUNTRYCODE from city where id>3000;
2.Query all attributes of TamilNadu district in the CITY table.The district code for
TamilNadu is TN..

Select * from city where DISTRICT = 'TN';


3.Query alldataoftheCITYTablewhereIDisgreaterthan4000.
Select * from CITY WHERE ID>4000;
4.Query the NAME and COUNTRY CODE of CITY Table where ID is greater
than 4000.
Select NAME,COUNTRYCODE from CITY WHERE ID>4000;
5.Query all data of the CITY Table where ID is greater than 3000
Select * from CITY WHERE ID>3000;
.

6.Query all attributes of every Indian city in the CITY table.The COUNTRYCODE
for India is IND.

Select * from City where countrycode='IND';


7.Query all columns for a city in CITY with the ID 4054.
Select * FROM CITY WHERE ID=4054;
8.Query the ID, NAME and COUNTRY CODE of CITY Table where ID
is greater than 3000

select ID, NAME, COUNTRYCODE FROM CITY WHERE ID>3000;


9.Query all attributes CITY table with name as "SRMCARE".
Select * from CITY WHERE NAME = 'SRMCARE';
10.Query all columns for all American cities in CITY with populations larger than
100000. The CountryCode for America is USA.

Select * from CITY WHERE POPULATION > 100000 AND


COUNTRYCODE='USA';
.

11.Query the NAME and COUNTRYCODE of CITY Table where ID is greater


than 3000 and Less than 4000.

Select NAME, COUNTRYCODE from CITY WHERE ID > 3000 AND ID<4000;

12.Query the list of CITY name sending with vowels(i.e.,a,e,i,o,u) from STATION.
Your result cannot contain duplicates.

Select DISTINCT CITY from station where RIGHT(CITY,1) IN


('a','e','i','o','u');

13.Query the list of CITY names from STATION which have vowels (i.e.,a,e, i, o,
and u) as first characters. Your result cannot contain duplicates.

Select DISTINCT CITY from STATION where left (CITY,1) in


('a','e','i','o','u');
14.Query the list of CITY names from STATION which have vowels (i.e., a, e,
i,o,andu) as both their first and last characters.Your result cannot contain
duplicates.

Select DISTINCT CITY FROM STATION WHERE LEFT(CITY,1)IN


('a','e','i','o','u') AND RIGHT(CITY,1) IN ('a','e','i','o','u');
.

15.Query the list of CITY names from STATION that donot end with vowels. Your
result cannot contain duplicates.

Select DISTINCT CITY from station where city not like '%a' AND city not
like '%e' AND city not like '%i' AND city not like '%o' AND city not like
'%u';
16.Query the list of CITY names from STATION that do not start with vowels.
Your result cannot contain duplicates.
Select DISTINCT CITY FROM STATION WHERE LEFT (CITY,1) NOT IN ('a','e','i','o','u');

17.Query the table of all American cities in CITY with populations larger than
120000. The CountryCode for America is USA.
Select * FROM CITY WHERE POPULATION > 120000 AND COUNTRYCODE='USA';

18.Query the list of CITY names from STATION that either do not start with
vowels or do not end with vowels. Your result cannot contain duplicates.
Select DISTINCT CITY FROM STATION WHERE LEFT (CITY,1) NOT IN ('a','e','i','o','u')
OR RIGHT(CITY,1) NOT IN ('a','e','i','o','u');
.

19.Query the ID, NAME and COUNTRY CODE of CITY Table where ID is
greater than 3000 and less than 4000.
Select ID, NAME , COUNTRYCODE FROM CITY WHERE ID > 3000 AND ID < 4000;

20.Query a list of CITY names from STATION with even ID numbers only. You
may print the results in any order, but must exclude duplicates from your answer.
select DISTINCT CITY FROM STATION where ID % 2 = 0;
21.Query the Name of any student in STUDENTS who scored higher than 75
Marks.Order your output by the last three characters of each name. If two or more
students both have names ending in the same last three characters (i.e.: Bobby,
Robby, etc.), secondary sort them by ascending ID.
SELECT Name FROM STUDENTS WHERE Marks > 75 ORDER BY RIGHT (Name, 3),ID;

22.Write a query that prints a list of employee names (i.e.:the name attribute) from
the Employee table in alphabetical order.
Select NAME from EMPLOYEE ORDER BY NAME;
.

23.Query the list of CITY names from STATION that do not start with vowels and
do not end with vowels. Your result cannot contain duplicates.
Select DISTINCT CITY FROM STATION WHERE LEFT (CITY,1) NOT IN
('a','e','i','o','u') AND RIGHT (CITY,1) NOT IN ('a','e','i','o','u');
24.Write a query that prints a list of employee names (i.e.: the name attribute) for
employees in Employee having a salary greater than $ 2000 per month who have been
employees for less than 10 months. Sort your result by ascending employee_id.
Select NAME FROM EMPLOYEE WHERE SALARY > 2000 AND MONTHS < 10 ORDER
BY EMPLOYEE_ID;

25.Query the list of CITY names starting with vowels (i.e. ,a ,e , i , o, or u)from
STATION. Your result cannot contain duplicates.
Select DISTINCT CITY FROM STATION WHERE LEFT (CITY,1) IN ('a','e','i','o','u');
.

26.Query list of CITY names from STATION with


evenIDnumbersonly. Youmayprinttheresultsin any order, but must
exclude duplicates from your answer.
selectdistinctCITYfromSTATIONwhereID%2=0;
27.Query the list of CITY names from STATION that do not start
with vowels and do not end with vowels . Your result cannot contain
duplicates.
selectdistinctCITYfromSTATIONwherecityregexp'^[^aeiou].*
[^aeiou]$';
28.Writeaquerythatprintsalistofemployeenames(i.e.: the name attribute)
from the Employee table in alphabetical order.
selectNAMEfromEMPLOYEEorderbyNAME;
29.Writeaqueryidentifyingthetypeofeachrecordinthe TRIANGLES table
using its three side lengths. Output one of the following statements for
each record in the table:
Equilateral: It's a triangle with 3 sides of equal length. Isosceles: It's
a triangle with 2 sides of equal length.
Scalene:It'satrianglewith3sidesofdifferinglengths. Not A Triangle:
The given values of A, B, and C don't form a triangle.
select
CASE
.

WHENA+B <=CORA+C <=BORB +C<=ATHEN'Not A


Triangle'
WHEN A = B AND B = C THEN 'Equilateral'
WHENA=BORA=CORB=CTHEN'Isosceles' WHEN
A <> B AND B <> C THEN 'Scalene'
END TRIANGLES
fromTRIANGLES;
30.Writeaquerythat printsalistofemployeenames(i.e.: the name attribute)
for employees in Employee having a salary greater than $2000 per
month who have been employees for less than 10 months. Sort your
result by ascending employee_id.
selectNAMEfromEMPLOYEEwheresalary>2000and months <
10 order by employee_id;
31.QuerythelistofCITYnamesstartingwithvowels(i.e., a, e, i, o, or u)
from STATION. Your result cannot contain duplicates.
selectdistinctCITYfromSTATIONwhereCITYRLIKE
'^[AEIOUaeiou]';
32.Generatethefollowingtworesult sets:
Query an alphabetically ordered list of all names in
OCCUPATIONS,immediatelyfollowedbythefirstletter of each
profession as a parenthetical (i.e.: enclosed in parentheses). For
example: AnActorName(A), ADoctorName(D), AProfessorName(P),
and ASingerName(S).
Querythenumberofocurrences ofeachoccupation in
.

OCCUPATIONS.Sorttheoccurrencesinascending order, and output


them in the following format:

There are a total of [occupation_count] [occupation]s.


where[occupation_count]isthenumberofoccurrences
ofanoccupationinOCCUPATIONSand[occupation]is the lowercase
occupation name. If more than one Occupation has the same
[occupation_count], they should be ordered alphabetically.

Note:Therewillbeatleast twoentriesinthetablefor each type of


occupation.
selectconcat(Name,'(',substr(occupation,1,1),')')as
from occupations order by N;
selectconcat('Thereareatotalof',count(occpation),'
',lower(occpation),'s'.)
fromoccpationsgroupbyoccpationorderby
count(occpation),occpation;
33.Query the Name of any student in STUDENTS who scored higher
than 75 Marks. Order your output by the last three characters of each
name. If two or more studentsbothhavenamesendinginthesamelastthree
characters (i.e.: Bobby, Robby, etc.), secondary sort them by ascending
ID.
selectNamefromSTUDENTSwheremarks>75ORDER BY
SUBSTR(Name,LENGTH(Name)-2,3),ID;
.

34.Writeaquerythatprintsthesumofthecustomerid, quantity and price.

Note:UseSQLin-builtFunctiontocalculatethesumof the tuples in


items_ordered table.

The statement has to return a single result which


containsthesumvaluecustomerid,quantityandprice columns of
everything returned in the items_orderedtable.
selectsum(customerid),sum(quantity),sum(price)from
items_ordered;
35.Displayallthedetailsfromtheitems_orderedtable by using (select *
from items_ordered table).

PerformAbsolutefunction(abs)forthecolumns customerid, price and


quantity respectively.

Note:Thefinalresultshouldhaveonlycustomerid,price and quantity.


selectabs(customerid),abs(price),abs(quantity)from
items_ordered;
36.PerformArithmeticOperations.

Displayallthedetailsfromtheitems_orderedtableby using (select * from


items_ordered table).

Perform arithmetic query by adding 113 in customer id


filed,multiply50inquantity,reducethepriceby50and
.

dividethecustomeridby100respectivelyandduly.

customerid+113
quantity*50 price-
50 customerid/100
selectcustomerid+113,quantity*50,price-
50,customerid/100 from items_ordered;
37.Writeaquerythatprints thesum andaverageof the customerid,
quantity and price.

Note:UseSQLin-builtFunctiontocalculatethesum and average of the


tuples in items_ordered table.

The statement has to return a single result which contains the sum
and average value of customerid,
quantityandpricecolumnsofeverythingreturnedin the
items_ordered table.

select
sum(customerid),sum(quantity),sum(price),avg(customerid),a
vg(quantity),avg(price) from items_ordered;
38.Write a query to display number of rows(Only
count)intheitems_orderedtableNote:UseSQLin- built Function to
find the count
selectcount(*)fromitems_ordered;
39.Write a query that prints the minimum of
customerid,quantityandpriceinitems_orderedtable.
.

Note:UseSQLin-builtFunctiontocalculateminimum of the tuples in


items_ordered table.

The statement has to return a single result which


containstheminimumvalueofcustomerid,quantity and price
columns of everything returned in the items_ordered table.
selectmin(customerid),min(quantity),min(price)from
items_ordered;
40.Forallofthetentsthatwereorderedinthe items_ordered table,
what is the price of the lowest tent?

Hint:Yourqueryshouldreturnthepriceonly.

Note:UseSQLin-builtFunctiontocalculate minimum value in tents


selectmin(price)fromitems_orderedwhereitem='tent';

41.Writeaquerythatprints theaverageoftheprice column.

Note:UseSQLin-builtFunctiontocalculatethe average of the price


column

The statement has to return a single result which


containstheaveragevalueofeverythingreturnedin the price column
from the items_ordered table.
.

selectavg(price)fromitems_ordered;
42.Write a query that prints the minimum and
maximumofcustomerid,quantityandpricein items_ordered
table.

Note:UseSQLin-builtFunctiontocalculateminimum and maximum of


the tuples in items_ordered table.

The statement has to return a single result which contains the


minimum and maximum value of
customerid,quantityandpricecolumnsofeverything returned in the
items_ordered table.
select
min(customerid),min(quantity),min(price),max(customerid
),max(quantity),max(price)fromitems_ordered;
43.UsageofASCIIValue=ReturnstheASCIIvalue for the specific
character.

ASCII(characterorcolumn name)

character = The character to return the ASCII value


for.Ifmorethanonecharacterisentered,itwillonly return the value
for the first character

Displaythenameandthe asciivaluecolumn (ASCII(name)) from


students table
selectname,ASCII(name)fromstudents;
44.NOW():TheNOW()functionreturnsthecurrent system date
and time.
.

Syntax:
SELECTNOW()FROMtable_name; Table

Name : emp

Columns

eid - Number name -


varchar age -
Number salary-
Number

Usenow()function aftersalarycolumninthequery.
selectEID,NAME,AGE,SALARY,NOW()fromemp;
45.MIDFunction:

MIDFunctionhasthreeparameters:

First Parameter = Column Name


SecondParameter=StartLength
ThirdParameter=Lengthofcharacterstobe displayed
Note:Indexstartsfrom1. Example:

MID(column_name,start,length)fromtable-name; Writea

FUNCTIONtodisplaythe salarycolumnof
.

employeetableusingmid function.

Thestartlength(index)is 1anddisplaytotalof4 characters in salary


column.

TableName:empColu
mns

eid - Number name -


varchar age - Number
salary–Number
selectmid(salary,1,4)fromemp;

46.Writeafunctiontoconvertallthenamesinthe column to upper


case.

TableName:empColu
mns

eid - Number name -


varchar age - Number
salary-Number

Note:UCASEfunctionissimilartoUPPERfunction.
UseUPPER Function
selectupper(name)fromemp;
.

47.Writeaquerytoaddthepopulationfiledfromcity table.

Note:UseSUMmethod
selectSUM(population)fromcity;
 48.Writeafunctiontoconvertallthenamesinthe column to lower
case.

TableName:empColu
mns

eid - Number name -


varchar age - Number
salary-Number

Note:LCASEfunctionissimilartoLOWERfunction. Use LOWER


Function

selectlower(name)fromemp;
49.Writeanquerytoexecute thesignfunctioninSQL.

TableName=Customersandthedescriptionfor customer table is as


follows:
selectsign(customerid)fromcustomers;
50.Inthistask,theuserneedstowriteaqueryto implement
Round and Square root function.

Note:UseSQLin-builtFunctiontocalculateround and square root


function for items_ordered table.
.

Theuserneedstoimplementroundandsquareroofunctionforthecolumnp
riceinitems_orderedtable.

RoundthepricemethodTWOdigits. Hint:

round(price,2)
selectround(price,2),sqrt(price)fromitems_ordered;
51.The"customers"tablehasfollowingfield

1. customerid
2. firstname
3. lastname
4. city
5. state

select*fromcustomersorderbystate;

52.The"customers"tablehasfollowingfield

1. customerid
2. firstname
3. lastname
4. city
5. state

select*fromcustomersorderbycityasc;
.

53.The"customers"tablehasfollowingfield

1. customerid
2. firstname
3. lastname
4. city
5. state

select*fromcustomersorderbyfirstnameasc;

54.The"city"tableconsistsoffollowingfields: 1.ID
2. NAME
3. COUNTRYCODE
4. DISTRICT
5. POPULATION

select*fromcityorderbypopulation;

55.The"customers"tablehasfollowingfield

1. customerid
.

2. firstname
3. lastname
4. city
5. State

select*fromCUSTOMERSorderbyfirstnamedesc;

56.The"suppliers"tablehasfollowingfield

1. SupplierID
2. SupplierName
3. ContactName
4. Address
5. City
6. PostalCode
7. Country
8.Phone

selectcityfromcustomersunionselectcityfromsuppliers order by
city desc;
.

57.The"city"tableconsistsoffollowingfields: 1.ID
2. NAME
3. COUNTRYCODE
4. DISTRICT
5. POPULATION

selectdistinctcountrycodefromcityorderbyCOUNTRYCODE
desc;

58.Writeaqueryusingajointodeterminewhich items were ordered by


each of the customers in the customers table.
.

Select the customerid, firstname, lastname, item,


andpriceforeverythingeachcustomerpurchased in the items_ordered
table.

Theitems_orderedtabledescriptionisasfollows:

selectcustomers.customerid, customers.firstname,
customers.lastname, items_ordered.item,
items_ordered.pricefromcustomersJOINitems_ordered
ON customers.customerid = items_ordered.customerid

59.You are given two tables: Students and


Grades.StudentscontainsthreecolumnsID, Name and
Marks.

SELECTIF(GRADES.GRADE>=8,STUDENTS.NAME,
NULL),GRADES.GRADE, STUDENTS.MARKS
FROMGRADES,STUDENTS
WHERESTUDENTS.MARKSBETWEENGRADES.MIN_MARK
AND GRADES.MAX_MARK
ORDERBYGRADES.GRADEDESC,STUDENTS.NAME;
.

60.Juliaaskedherstudentstocreatesomecoding challenges. Write a query to


print the hacker_id, name, and the total number of challenges created by
each student. Sort your results by the total
numberofchallengesindescendingorder.Ifmore than one student created
the same number of challenges, then sort the result by hacker_id. If more
than one student created the same number of challenges and the count is
less than the maximum number of challenges created, then exclude those
students from the result

InputFormat

Thefollowingtablescontainchallengedata:

Hackers:Thehacker_idistheidofthehacker, and name is the name


of the hacker.

Challenges: The challenge_id is the id of the


challenge,andhacker_idistheidofthestudent who created the
challenge.

SELECTH.HACKER_ID,
.

H.NAME,
COUNT(C.CHALLENGE_ID)ASC_COUNT
FROM HACKERS H
JOINCHALLENGESCONC.HACKER_ID=H.HACKER_ID
GROUP BY H.HACKER_ID, H.NAME
HAVINGC_COUNT=
(SELECTCOUNT(C2.CHALLENGE_ID)ASC_MAX
FROM CHALLENGES AS C2
GROUP BY C2.HACKER_ID
ORDERBYC_MAXDESCLIMIT1)
ORC_COUNTIN
(SELECTDISTINCTC_COMPAREASC_UNIQUE FROM
(SELECT H2.HACKER_ID,
H2.NAME,
COUNT(CHALLENGE_ID)ASC_COMPARE
FROMHACKERSH2

JOINCHALLENGESCONC.HACKER_ID=H2.HACKER_ID
GROUP BY H2.HACKER_ID, H2.NAME) COUNTS
GROUP BYC_COMPARE
HAVING COUNT(C_COMPARE) = 1)
ORDERBYC_COUNTDESC,H.HACKER_ID;
.

61.GiventheCITYandCOUNTRYtables,query the names of all the


continents (COUNTRY.Continent) and their respective average city
populations (CITY.Population) rounded down to the nearest integer.

Note:CITY.CountryCodeandCOUNTRY.Code are matching key


columns.

select
COUNTRY.CONTINENT,FLOOR(AVG(CITY.POPULATION))
FromCITY
joinCOUNTRYonCITY.CountryCode=COUNTRY.Code group
by COUNTRY.Continent;
.

62.GiventheCITYandCOUNTRYtables,query thesum
ofthepopulationsofallcities wherethe CONTINENT is 'Asia'.

Note:CITY.CountryCodeandCOUNTRY.Code are matching key


columns.

selectSUM(CITY.POPULATION)fromCITYjoinCOUNTRYon
COUNTRY.Code=CITY.CountryCodewhere
COUNTRY.Continent = 'Asia';

63.GiventheCITYandCOUNTRYtables,query
thenamesofallcitieswheretheCONTINENTis Africa.

Note:CITY.CountryCodeandCOUNTRY.Code are matching key


columns.
.

selectCITY.NAMEfromCITYjoinCOUNTRYon COUNTRY.Code
= CITY.CountryCode where COUNTRY.Continent = 'Africa';
64.WriteaQuerytoJoin thefollowingtablesandfind the number of rows
in the table using count function

Table1=items_ordered Table 2 =
submissions

Hint:UseCountFunctionandUnionAlltoaddboth the tables


selectcount(*)fromitems_orderedUnionAllselectcount(*) from
submissions;
65.WriteaQuerytoJointhefollowingtables

Table 1 = Difficulty
Table2=Departments

select*fromDifficultyUnionselect*from
Departments;
66.WriteaQuerytoJointhefollowingtables -Use Right Join

1.Wehaveatablecalledjoins_supplierswithtwo fields (supplier_id and


supplier_name)

2.Wehaveanothertablecalledorderswiththree
.

fields(order_id,supplier_id,andorder_date)

Writethequerytogetthefollowingresultset

supplier_idsupplier_nameorder_year 10000 IBM


2013
10001HewlettPackard2013
10002Microsoft
10003NVIDIA

selectjoins_suppliers.supplier_id,
joins_suppliers.supplier_name,
orders.order_year from
joins_suppliersLeftOuterJoinorderson
joins_suppliers.supplier_id
=orders.supplier_id;
67.WriteaQuerytoJointhefollowingtables -Use Inner Join

1. Wehaveatablecalledjoins_supplierswithtwo fields
(supplier_id and supplier_name)

2. Wehaveanothertablecalledorderswiththree fields (order_id,


supplier_id, and order_date)

Writethequerytogetthefollowingresultset
.

supplier_idnameorder_year 10000 IBM


2013
10001HewlettPackard2016

selectjoins_suppliers.supplier_id,
joins_suppliers. supplier_name,
orders.order_yearfromjoins_suppliersInner
Join orders on
joins_suppliers.supplier_id=
orders.supplier_id;
68.Write a query using a join to determine which
itemswereorderedbyeachofthecustomersinthe customers table.

Selectthecustomerid,firstname,lastname,item,and price for everything


each customer purchased in the items_ordered table.

selectcustomers.customerid,
customers.firstname,customers.lastname,
items_ordered.item, items_ordered.price
from customers JOIN items_ordered ON
customers.customerid =
items_ordered.customerid;
.

69.WriteaQuerytoJointhefollowingtables

Table1=Difficulty Table
2 = hackers

select*fromDifficultyUnionAllselect*from hackers;
70.WriteaQuerytoJointhefollowingtables

Table1=submissions Table 2 =
hackers

Select name field from "submission" table and join the "hackers"
table using the common hacker_id
columnfromboththetable(submissionstableand hackers table).

selectjoins_suppliers.supplier_id,joins_suppliers.
supplier_name,
orders.order_yearfromjoins_suppliersInnerJoin orders on
joins_suppliers.supplier_id=orders.supplier_id;
71.Write a query to display all the information of the
employeeswhosesalaryiswithintherange1000and 3000

SELECT*FROMsub_employeesWHEREsalary BETWEEN
(SELECT 1000) AND 3000;
.

72.Writeaquerytodisplaytheemployeename(first name and last name ) for


all employees in the same department as Clara. Exclude Clara.

select*fromsub_employees;
73.Write a query to display the name ( first name
andlastname)forthoseemployeeswhogetsmore salary than the employee
whose ID is 163

selectfirst_name, last_name from sub_employees


wheresalary>(selectsalaryfromsub_employees where
employee_id = 163);
74.Write a query to display the name ( first name and last name ), salary,
department id, job id for thoseemployeeswhoworksinthesamedesignation
as the employee works whose id is 169.

SELECT first_name, last_name, salary,


department_id,job_idFROMsub_employees WHERE
job_id =( SELECTjob_id FROM
sub_employeesWHEREemployee_id=169);
75.Write a query to display the employee id, employee name (first
name and last name ) for all
employeeswhoearnmorethantheaveragesalary

SELECT employee_id, first_name,last_name FROM


sub_employees WHERE salary > ( SELECT
AVG(salary) FROM sub_employees);
.

76.Write a query to display the name ( first name and last name ),
salary, department id for those employeeswhoearnsuchamountof
salarywhichis the smallest salary of any of the departments.

SELECT first_name, last_name, salary, department_id


FROM sub_employees WHERE
salary IN ( SELECT MIN(salary)FROM
sub_employees GROUP BY department_id);
77.Write a query to display all the information of an
employeewhosesalaryandreportingmanager_idis 3000 and 121
respectively.

SELECT * FROM sub_employees WHERE


(salary,manager_id)=(SELECT3000,121);
78.Writeaquerytodisplayalltheinformationof the employees
whose salary is within the range of smallest salary and 2500

SELECT*FROMsub_employeesWHEREsalary
BETWEEN (SELECT MIN(salary)FROM
sub_employees)AND2500;
79.Displayalltheinformationofanemployeewhose id is any of the number
134, 159 and 183.

Tablename=sub_employees

SELECT*FROMsub_employeesWHERE employee_id IN
(134,159,183);
.

80.CreateaVIEWasyourRegistrationNumber_01.

For example your registration number is


RA1511003010255thecreateaviewas
RA1511003010255_01.

TheviewshouldbecreatedforCITYtableforthe following fields:

1. ID
2. NAME
3. COUNTRYCODE
Aftercreatingviewfortheabove mentionedfields display the view.

select*fromRA1511003010255_01;
81.CreateaVIEWasyourRegistrationNumber_02.

For example your registration number is


RA1511003010255thecreateaviewas
RA1511003010255_02.

Theviewshouldbecreated forCustomerstablefor the following fields:

1. firstname
2. city
3. state
.

Aftercreatingviewfortheabovementionedfields display the view.

select*fromRA1511003010255_02;
82.CreateaVIEWasyourRegistrationNumber_10.

For example your registration number is


RA1511003010255thecreateaviewas
RA1511003010255_10.

Theviewshouldbecreatedforcountriestableforthe following fields:

1. country_id
2. country_name

Aftercreatingviewfortheabovementionedfields display the view

SELECTcountry_id,country_nameFROM
RA1511003010255_10;
83.SELECTcountry_id,country_nameFROM
RA1511003010255_10;

SELECTemployee_id,name,salaryFROM
RA1511003010255_03;
84.CreateaVIEWasyourRegistrationNumber_05.

For example your registration number is


RA1511003010255thecreateaviewas
RA1511003010255_05.
.

Theviewshouldbecreatedforlocationstableforthe following fields:

1. location_id
2. street_address
3. country_id
Aftercreatingviewfortheabove mentionedfields display the view.

SELECTlocation_id,street_address,country_id FROM
RA1511003010255_05;
85.CreateaVIEWasyourRegistrationNumber_08.

For example your registration number is


RA1511003010255thecreateaviewas
RA1511003010255_08.

TheviewshouldbecreatedforCountrytableforthe following fields:

1. CODE
2. NAME
3. GNP
Aftercreatingviewfortheabovementionedfields display the view.

SELECTCODE,NAME,GNPFROM
RA1511003010255_08;
86.Create a VIEW as your RegistrationNumber_06.
For example your registration number is RA1511003010255 the create a view as
RA1511003010255_06.

The view should be created for suppliers table for the following fields:

1. SupplierID
2. SupplierName
3. Address
4. Phone

After creating view for the above mentioned fields display the view.
.

Hint:

1. Create a view with specified name.


2. After creating the view delete the lines in the code editor
3. Display the view (select * from viewname)

SELECT SupplierID,SupplierName, Address ,Phone FROM


suppliers;

87. Create a VIEW as your RegistrationNumber_06.

For example your registration number is RA1511003010255 the


create a view as RA1511003010255_06.

The view should be created for suppliers table for the following
fields:

1. SupplierID
2. SupplierName
3. Address
4. Phone

After creating view for the above mentioned fields display the
view.

Hint:

1. Create a view with specified name.


2. After creating the view delete the lines in the code editor
3. Display the view (select * from viewname)

SELECT SupplierID,SupplierName, Address ,Phone FROM suppliers;

88. Create a VIEW as your RegistrationNumber_09.

For example your registration number is RA1511003010255 the


create a view as RA1511003010255_09.

The view should be created for Country table for the following
fields:

1. CODE
.

2. NAME
3. GNP
4. INDEPYEAR
5. SURFACEAREA

After creating view for the above mentioned fields display the
view.

Hint:

1. Create a view with specified name.


2. After creating the view delete the lines in the code editor
3. Display the view (select * from viewname)

SELECT CODE, NAME, GNP, INDEPYEAR, SURFACEAREA


FROM Country ;

89. Create a VIEW as your RegistrationNumber_07.

For example your registration number is RA1511003010255 the


create a view as RA1511003010255_07.

The view should be created for suppliers table for the following
fields:

1. SupplierID
2. SupplierName
3. ContactName
4. City

After creating view for the above mentioned fields display the
view.

Hint:

1. Create a view with specified name.


2. After creating the view delete the lines in the code editor
3. Display the view (select * from viewname)

SELECT SupplierID, SupplierName, ContactName, City FROM


.

RA1511003010255_07;

90. Create a VIEW as your RegistrationNumber_04.

For example your registration number is RA1511003010255 the


create a view as RA1511003010255_04.

The view should be created for items_ordered table for the following
fields:

1. item
2. price

After creating view for the above mentioned fields display the view.

Hint:

1. Create a view with specified name.


2. After creating the view delete the lines in the code editor
3. Display the view (select * from viewname)

select item,price from items_ordered ;

91. Create a VIEW as your RegistrationNumber_05.

For example your registration number is RA1511003010255 the


create a view as RA1511003010255_05.

The view should be created for locations table for the following
fields:

1. location_id
2. street_address
3. country_id

After creating view for the above mentioned fields display the view.
.

Hint:

1. Create a view with specified name.


2. After creating the view delete the lines in the code editor
3. Display the view (select * from viewname)
SELECT location_id, street_address, country_id FROM
RA1511003010255_05;

92. Create a VIEW as your RegistrationNumber_01.

For example your registration number is RA1511003010255 the create a view


as RA1511003010255_01.

The view should be created for CITY table for the following fields:

1. ID
2. NAME
3. COUNTRYCODE

After creating view for the above mentioned fields display the view.

Hint:

1. Create a view with specified name.


2. After creating the view delete the lines in the code editor
3. Display the view (select * from viewname)

select * from RA1511003010255_01;

93. Create a VIEW as your RegistrationNumber_03.

For example your registration number is RA1511003010255 the create a view


as RA1511003010255_03.

The view should be created for employee table for the following fields:

1. employee_id
2. name
3. salary

After creating view for the above mentioned fields display the view.

Hint:
.

1. Create a view with specified name.


2. After creating the view delete the lines in the code editor
3. Display the view (select * from viewname)
SELECT employee_id, name, salary FROM RA1511003010255_03;

94. Create a VIEW as your RegistrationNumber_02.

For example your registration number is RA1511003010255 the create a view


as RA1511003010255_02.

The view should be created for Customers table for the following fields:

1. firstname
2. city
3. state

After creating view for the above mentioned fields display the view.

Hint:

1. Create a view with specified name.


2. After creating the view delete the lines in the code editor
3. Display the view (select * from viewname)

select * from RA1511003010255_02;

95. Create a VIEW as your RegistrationNumber_08.

For example your registration number is RA1511003010255 the create a view


as RA1511003010255_08.

The view should be created for Country table for the following fields:

1. CODE
2. NAME
3. GNP

After creating view for the above mentioned fields display the view.

Hint:

1. Create a view with specified name.


2. After creating the view delete the lines in the code editor
3. Display the view (select * from viewname)
.

SELECT CODE, NAME, GNP FROM RA1511003010255_08;

96. Create a VIEW as your RegistrationNumber_10.

For example your registration number is RA1511003010255 the create a view


as RA1511003010255_10.

The view should be created for countries table for the following fields:

1. country_id
2. country_name

After creating view for the above mentioned fields display the view.

Hint:

1. Create a view with specified name.


2. After creating the view delete the lines in the code editor
3. Display the view (select * from viewname)

SELECT country_id, country_name FROM RA1511003010255_10;

97. In this task, the user needs to write a query to implement Round, Power
and Square root function.

Note: Use SQL in-built Function to calculate round, power and square root
function for station table.

The user needs to implement round, power and square root function for the
column lat_n and long_w and ID in customers table

Round the lat_n method to TWO digits.

1. Hint: round(lat_n , 2).

2. For power function :

Use lat_n value as one parameter "x" value and the "y" as 5.
Note: power(x,y) X= value denoted , lat_n and Y denotes="5"

Use long_w value as one parameter "x" value and the "y" as 7.
Note: power(x,y) X= value denoted , long_w and Y denotes="7"
.

3. Square root function for column ID.

Input Format

The station table is described as follows:

select round(price,2), sqrt(price) from items_ordered


;

98. Write a query using a join to determine which items were ordered
by each of the customers in the customers table.

Select the customerid, firstname, lastname, and item for each


customer purchased in the items_ordered table.

However display the results sorted by state in Ascending order.


(Order the Customerid in Ascendingorder)

The items_ordered table description is as follows:

select customers.customerid, customers.firstname, customers.lastname,


items_ordered.item, items_ordered.price from customers JOIN
items_ordered ON customers.customerid = items_ordered.customerid
ORDER BY customers.state ASC, customers.customerid ASC;

99. Write a query using a join to determine which items were


ordered by each of the customers in the customers table.

Select the customerid, firstname, lastname, and item for each


customer purchased in the items_ordered table.

However display the results sorted by state in descending order.


(Order the Last name in Descending order)

The items_ordered table description is as follows:


SELECT customerid, firstname, lastname, item
FROM customers
JOIN items_ordered io ON customerid = customerid
ORDER BY state DESC, lastname DESC;
.

100. Write a query using a join to determine which items were


ordered by each of the customers in the customers table.

Select the customerid, firstname, lastname, and item for each


customer purchased in the items_ordered table.

However display the results sorted by state in Ascending order.


(Order the Customerid in Ascendingorder)

The items_ordered table description is as follows:

select customers.customerid, customers.firstname, customers.lastname,


items_ordered.item, items_ordered.price from customers JOIN
items_ordered ON customers.customerid = items_ordered.customerid
ORDER BY customers.state ASC, customers.customerid ASC;

You might also like