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

SQL Querie Problems for Practice (3)

The document contains a series of SQL commands and queries related to various tables including Student, Employee, Stock, Travel, Product, Client, and Vehicle. It includes tasks such as displaying records, inserting data, updating values, and performing joins between tables. The queries cover a range of operations including filtering, counting, and sorting based on different criteria.

Uploaded by

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

SQL Querie Problems for Practice (3)

The document contains a series of SQL commands and queries related to various tables including Student, Employee, Stock, Travel, Product, Client, and Vehicle. It includes tasks such as displaying records, inserting data, updating values, and performing joins between tables. The queries cover a range of operations including filtering, counting, and sorting based on different criteria.

Uploaded by

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

1.

Create the above student relation with given


fields and tuples. Primary key is ROLLNO.
2. Insert all the records.
3. Display all the record of the table student.
4. Display all the values whose roll no is 2.
5. Display all the values whose Gender is ‘M’.
6. Display all the values whose marks is greater than 80.
7. Display all the values whose stream is ‘Science’.
8. Display all the values whose DOB is greater than ‘2000-01-01’.
9. Display Roll No, Name, Stream from the relation student.
10. Display all the values whose gender is ‘M’ and stream is ‘Science’.
11. Display Name and Marks of those student whose gender is Female and
stream is commerce.
12. Display the details whose name start with ‘R’.
13. Display the details whose name last character is ‘a’.
14. Count all the male students.
15. Count all the female students whose marks is greater or equal to
80.
16. Modify/update/change the marks from 82 to 72 of those student
whose rollno is 5 .
17. Display name, dob and mobile no of all the male students who opted
science stream.
18. Display the average marks of science department.
EMPLOYEE
EMP_I EMP_NAME DEPARTMENT HIREDATE GENDER ADDRESS SALARY
D
1001 RAM SINGH HUMAN 14-DEC-2011 M LUCKNOW 12000
RESOURCE
1002 KRISHAN IT 12-APR-2010 M LUCKNOW 15000
PAWAR
1003 MAHAK ACCOUNTS 25-JUNE-2015 F KANPUR 13540
SINGH
1004 TINA RANI HUMAN 15-JAN-2000 F ALLAHABA 16000
RESOURCE D
1005 KAMAL ACCOUNTS 18-MAR-2012 M KANPUR 20000
KISHOR
1006 RaJ Kishor IT 15-APR-2009 M DELHI 25000
1007 Kavita Singh FINANCE 25-OCT-2010 F KANPUR NULL
1008 Reema IT 14-DEC-2011 F LUCKNOW NULL
1009 Jeet kumar ACCOUNTS 05-APR-2008 M BARABANKI 23000

1010 Trapti FINANCE 10-MAY-2016 F LUCKNOW 25600


1. Display all the details from the table Employee.
2. Display all the details of employee where emp_id is 1002.
3. Display all the details of employee whose name is ‘ Mahak Singh’.
4. Display Emp id, name, department, salary of all the employees.
5. Display emp id, name, department and salary of those employees whose
emp id is 1004.
6. Display employee name and salary of all the employees whose salary is
greater than 13000.
7. Display all the details of all employees whose department is ‘Human
Resource’.
8. Display the details of all the employees whose salary is less than or equal
to 15000.
9. Display the details of all the employees whose department is IT and
Address is Lucknow.
10. Display the details of all the employees whose department is Accounts
and Address is Lucknow.
11. Display the details of all the employees whose department is IT or
Address is Lucknow.
12. Display the details of all the employees whose gender is ‘M’ and
working is ‘Accounts’.
1. To display details of all the Items in the Stock table in ascending
order of StockDate.
2. To display details of those Items in Stock table whose Dealer
Code(Dcode) is 102 or quantity in Stock(Qty) is more than 100.
3. To insert a record in the Stock table with the values:
(5010, ‘Pencil HB’, 102, 500, 10, ‘2010-01-26’)
4. To count total no of items whose Dcode is 102.
5. To display the details Dcode wise.
6. To display the maximum and minimum unit price of items.
7. To display item no and item name of those items whose name start
with ‘E’.
8. To display item no and item name of those items whose name ends
with ‘c’.
9. To display all the details of those items whose name contain ‘e’ as
middle character.
10. To display the average of unitprice of items with iteem name wise.
1. To display NO,NAME, TDATE from the table TRAVEL in descending order of
NO.
2. To display the NAME of all the travellers from the table TRAVEL who are
travelling by vehicle with the code 101 or 102.
3. To display the NO and NAME of all the travellers from the table TRAVEL who
travelled between ‘2015-12-31’ and 2015-04-01’.
4. To display all the details from table TRAVEL for the travellers who have
travelled distance more than 100 Km in ascending order of NOP.
5. To display the distinct CODE of the travellers.
6. To display details of those travellers whose names are ‘Janish Kin’, Tarun
Ram’, ‘John Fen’.
7. To display all the details of travellers whose distance between 100 to 300
KM.
8. To display all the details of travellers whose name starts with ‘J’.
9. To display all the details of travellers whose name ends with ‘a’.
10. Display the sum of all the distance in KM CODE wise.
Find the output of given SQL commands:
11. select count(*),CODE from TRAVEL group by CODE having count(*)>1;
12. select CODE,NAME,TDATE from TRAVEL where KM<90;
13. select max(KM) from TRAVEL.
14. select * from TRAVEL order by TDATE.
1. To display the details of those product whose P_ID is FW05.
2. To display the details of products whose Price is in the range of 50 to 100(both values
included).
3. To display the details of those product whose name ends with Wash.
4. To display sum of all the prices whose Manufacturer is ABC.
5. To display P_ID, ProductName and ExpiryDate of those product whose more than ‘2010-
09-10’.
OUTPUT BASED
6. SELECT Manufacturer, max(Price), min(Price), Count(*) FROM Product GROUP BY
Manufacturer.
7. SELECT ProductName, Price * 4 FROM Product.
8. SELECT avg(Price) from Prodcut group by Manufacturer;
9. SELECT * FROM PRODCUT WHERE P_ID LIKE ‘F%’;
1. To display the details of those Client whose C_ID is greater than 10.
2. To display the details of those clients whose City is Delhi.
3. To display the details of those Clinet whose ClientName ends with ‘e’.
4. To display details of all the Clinet whose P_ID IS Null.
5. To display C_ID, ClientName and City of those Client whose P_ID ends with ‘1’.
OUTPUT BASED
6. SELECT DISTINCT CITY FROM CLIENT;
7. SELECT CLIENTNAME, CITY FROM CLIENT WHERE CITY=‘DELHI’.
8. UPDATE CLIENT SET CLIENTNAME=‘OLIVE’ WHERE C_ID=16;
9. ALTER TABLE CLIENT ADD TOTALEXPENCE INT;
10. TO UPDATE THE VALUE IN TOTALEXPNCE AS FOLLOWS:1 – 1000, 6 – 2000, 12 – 5500,
15 – 6800, 16 – 1200, 14 – 2500.
TWO TABLES JOINING QUERIES
1. To display the P_ID, PRODUCTNAME, CLIENTNAME
FROM TABLE PRODUCT AND CLIENT.
2. To display the P_ID, PRODUCTNAME, CLIENTNAME
FROM TABLE PRODUCT, CLIENT WHERE CLIENT NAME
ends with ‘e’.
3. To display P_ID, PRODUCTNAME, MANUFATRURER,
PRICE, CLIENTNAME, CITY FROM PROEUCT AND CLIENT
WHOST CITY IS DELHI.
4. To display P_ID, PRODUCTNAME, PRICE, CLIENTNAME,
CITY FROM PROEUCT AND CLIENT WHERE PRICE IS
GREATER THAN 50.
5. To display P_ID, PRODUCTNAME, C_ID, ClientName and
City of those PROECUT ,Client whose MANUFACTURER IS
‘XYZ’.
TWO TABLES JOINING QUERIES
1. To display all details from customer, transact.
2. To display the customer name, address, transaction no,
amount, type of amount from customer, transact.
3. To display account no, customer name, gender, amount,
date of transaction from customer, transact.
4. To display account no, customer name, address, amount,
date of transaction from customer, transact where
amount is greater than 2000.
5. To display account no, customer name, address, amount,
date of transaction from customer account no wise.
6. To display account no, customer name, address, type of
account from customer, transact where customer name
end with ‘Kumar’.
Table: SAP
SAPID ItemCode ItemName ItemStorageLocation
S1001 1001 Receiver W12-B3-R24

S1002 1002 Transponder W13-B7-R87

S1003 1003 Battery Bank W21-B1-R87

S1004 1004 Inverter W21-B11-R2


Table : Store
S1005
StoreID 1005
Item Code Genset
StoreLocation W22-B15-R16
ReceivedDate
1201 1001 Hauz Khas 2016/05/20
1202 1002 Rajouri Garden 2016/06/14
1203 1003 Rohini 2016/05/06
1204 1004 Hauz Khaas 2016/07/15
1205 1005 Rajendra Place 2016/05/27

Write SQL Commands for the following:


1)To display the ItemCode, ItemName and ReceivedDate of all the items .
2)To display details of items in descending order of their names.
3)To display SAPID, ItemName, ItemStorageLocation of all the items
whose received date is after 2nd May 2016.
4) To display SAPID, ItemName, StoreID of all those items whose store
location is “HauzKhas”
Table: Vcode VehicleName Make Color Capacity Charges
CABHUB 100 Innova Toyota WHITE 7 15
102 SX4 Suzuki BLUE 4 14
104 C Class Mercedes RED 4 35
105 A-Star Suzuki WHITE 3 14
108 Indigo Tata SILVER 3 12

Table: CCode CName VCode


CUSTOMER 1 Hemant Sahu 101
2 Raj Lal 108
3 Feroza Shah 105
4 Ketan Dhal 104

Write SQL commands for the following statements:


1) To display the names of all white colored vehicles
2) To display name of vehicle, make and capacity of vehicles in ascending
order of their sitting capacity
3) To display the highest charges at which a vehicle can be hired from CABHUB.
4) To display the customer name and the corresponding name of the vehicle
hired by them.
(a)Give the output of the following SQL queries:
1)SELECT COUNT(DISTINCT Make) FROM CABHUB;
2)SELECT MAX(Charges), MIN(Charges) FROM CABHUB;
3)SELECT COUNT(*), Make FROM CABHUB GROUP BY Make;
4)SELECT VehicleName FROM CABHUB WHERE Capacity = 4;
(Vi) SELECT CompName, ‘Mr. ’ , ContactPerson FROM Company
WHERE CompName LIKE ‘%a’;
(a) To display the name of all Games.
(b) To display details of those games which are having PrizeMoney
more than 7000.
(c) To display the content of the Games table in ascending order of
ScheduleDate.
(d) To display day of week those Prize money is less than 10000.
(e) To Display the all Record those prizeMoney in
4000,5000,9000,10000,15000.
(f) To display the prizeMoney with Rs. 100 increment.
(g) To display the GameName last 5 characters.
(a) To show all the information about the student of History dept.
Ans: SELECT * FROM FRIENDS WHERE DEPT= ‘HISTORY’;
(b) To list the names of female students who are in Hindi dept.
Ans: SELECT NAME FROM FRIENDS WHERE DEPT= ‘HINDI’ AND SEX=’F’;
(c) To list names of all students with their date of admission in ascending order.
ANS : SELECT NAME FROM FRIENDS ORDER BY Dateofadm;
(d) To display student’s name, fee, age for male students only.
ANS: SELECT NAME, FEE, AGE FROM FRIENDS WHERE SEX= ‘M’;
(e) To count the number of students with age<23.
ANS : SELECT COUNT(*) FROM WHERE AGE<23;
(f) Modify the rows for computer department’s fees by increasing Rs. 100.
ANS : UPDATE FRIENDS SET FEE=FEE+100 WHERE DEPT= ‘Computer’;
(g) To display name of day those Fees is less than or equal300.
SELECT DAYNAME(DATEOFADM) FROM FRIENDS WHERE FEE<=300;
(h) To display the Month name first three characters those who are female.
SELECT MONTHNAME(LEFT(DATEOFADM),3) FROM FRIENDS WHERE
SEX= ‘F’;
(i) To show the output of following Query:-
(a) SELECT name, age,dateofadm,dateofadm+2 FROM FriendsWhere Sex=
‘M’;
(b) SELECT name,dateofadm,dateofadm +565/24 FROM Friends Where Sex=
‘F’
i. View Name and salary of all employees.
ii. List Name, designation and salary of all Clerks.
iii. Display id, Name and salary of all employees.
iv. Display Name and salary of all employees having
salary more than 40000
V. Display id,Name and salary of those employees whose
designation is ‘Clerk’.
vi. Display Name, Designation salary and PhoneNo of all
the employees in ascending
Order by salary.

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