12 Ip Pyq - SQL WS
12 Ip Pyq - SQL WS
2 Write the output of the following SQL command. select round(49.88); 2021
(A) 49.88 (B) 49.8 (C) 49.0 (D) 50 SQP
4 The ____________command can be used to makes changes in the rows of a table in SQL. 2021
SQP
5 Consider the table STUDENT given below: 2021
RollNo Name Class DOB Gender City Marks SQP
1 Anand XI 6/6/97 M Agra 430
2 Chetan XII 7/5/94 M Mumbai 460
3 Geet XI 6/5/97 F Agra 470
4 Preeti XII 8/8/95 F Mumbai 492
5 Saniyal XII 8/10/95 M Delhi 360
6 Maakhiy XI 12/12/94 F Dubai 256
7 Neha X 8/12/95 F Moscow 324
8 Nishant X 12/6/95 M Moscow 429
(B)
(C) (D)
III) Prachi has given the following command to obtain the highest marks
Select max(marks) from student where group by class;
but she is not getting the desired result. Help her by writing the correct command.
(A) Select max(marks) from student where group by class;
(B) Select class, max(marks) from student group by marks;
(C) Select class, max(marks) group by class from student;
(D) Select class, max(marks) from student group by class;
IV) State the command to display the average marks scored by students of each gender who
are in class XI?
i. Select gender, avg(marks) from student where class= “XI” group by gender;
ii Select gender, avg(marks) from student group by gender where class=”XI”;
iii. Select gender, avg(marks) group by gender from student having class=”XI”;
iv. Select gender, avg(marks) from student group by gender having class = “XI”;
Choose the correct option:
(A) Both (ii) and (iii) (B) Both (ii) and (iv)
(C) Both (i) and (iii) (D) Only (iii)
V) Help Ritesh to write the command to display the name of the youngest student?
(A) select name,min(DOB) from student ;
(B) select name,max(DOB) from student ;
(C) select name,min(DOB) from student group by name ;
(D) select name,maximum(DOB) from student;
6 Which type of values will not be considered by SQL while executing the following 2023
statement? SQP
SELECT COUNT(column name) FROM inventory;
(A) Numeric value (B) text value (C) Null value (D) Date value
7 If column “Fees” contains the data set (5000,8000,7500,5000,8000), what will be the output 2023
after the execution of the given query? SQP
SELECT SUM (DISTINCT Fees) FROM student;
(A) 20500 (B) 10000 (C) 20000 (D) 33500
8 Which SQL statement do we use to find out the total number of records present in the table 2023
ORDERS? SQP
(A) SELECT * FROM ORDERS; (B) SELECT COUNT (*) FROM ORDERS;
(C) SELECT FIND (*) FROM ORDERS; (D) SELECT SUM () FROM ORDERS;
1 Which one of the following functions is used to find the largest value from the given data in 2023
0 MySQL? SQP
(A) MAX( ) (B) MAXIMUM( ) (C) BIG( ) (D) LARGE( )
1 In SQL, which function is used to display current date and time? 2023
1 (A) Date () (B) Time () (C) Current () (D) Now () SQP
1 Which of the following is the correct output of the following SQL command? 2023
2 SELECT ROUND (7876.4568, 2);
(A) 7876.46 (B) 7876.45 (C) 7900 (D) 7900.4568
1 Ravisha has stored the records of all students of her class in a MYSQL table. Suggest a 2023
4 suitable SQL clause that she should use to display the names of students in alphabetical
order.
(A) SORT BY (B) ALIGN BY (C) GROUP BY (D) ORDER BY
1 To remove the leading and trailing space from data values in a column of MySql Table, we 2023
5 use
(A) Left( ) (B) Right( ) (C) Trim( ) (D) Ltrim( )
1 Predict the output of the following query: SELECT MOD (9,0); 2024
8 (A) 0 (B) NULL (C) NaN (D) 9 SQP
1 Which of the following SQL functions does not belong to the Math functions category? 2024
9 (A) POWER() (B) ROUND() (C) LENGTH() (D) MOD() SQP
2 Raj, a Database Administrator, needs to display the average pay of workers from those 2024
0 departments which have more than five employees. He is experiencing a problem while SQP
running the following query:
SELECT DEPT, AVG(SAL) FROM EMP WHERE COUNT(*) > 5 GROUP BY DEPT;
Which of the following is a correct query to perform the given task?
(A) SELECT DEPT, AVG(SAL) FROM EMP WHERE COUNT(*) > 5 GROUP BY DEPT;
(B) SELECT DEPT, AVG(SAL) FROM EMP HAVING COUNT(*) > 5 GROUP BY DEPT;
(C) SELECT DEPT, AVG(SAL) FROM EMP GROUP BY DEPT WHERE COUNT(*) > 5;
(D) SELECT DEPT, AVG(SAL) FROM EMP GROUP BY DEPT HAVING COUNT(*) > 5;
2 Predict the output of the following query: SELECT LCASE (MONTHNAME ('2023-03-05')); 2024
1 (A) May (B) March (C) May (D) march SQP
2 What will be the output of the following query? SELECT POWER(2,MOD(17,3)); 2024
4 (A) 8 (B) 1 (C) 0 (D) 4
2 Which MySQL command helps to add a primary key constraint to any table that has already 2024
6 been created?
(A) UPDATE (B) INSERT INTO (C) ALTER TABLE (D) ORDER BY
2 What will be the output of the following query? SELECT SUBSTR("G20 2023 INDIA", 5, 4); 2024
7 (A) G20 2 (B) 2023 (C) INDI (D) 023
2 Which of the following clause cannot work with SELECT statement in MYSQL? 2024
8 (A) FROM (B) INSERT INTO (C) WHERE (D) GROUP BY
2 Which MySQL string function is used to extract a substring from a given string based on a 2024
9 specified starting position and length?
(A) SUBSTRING_INDEX() (B) LENGTH() (C) MID() (D) TRIM()
3 The purpose of WHERE clause in a SQL statement is to: 2025
0 (A) Create a table (B) Filter rows based on a specific condition SQP
(C) Specify the columns to be displayed (D) Sort the result based on a column
3 Identify the SQL command used to delete a relation (table) from a relational database. 2025
1 (A) DROP TABLE (B) REMOVE TABLE (C) DELETE TABLE (D) ERASE TABLE SQP
3 Assertion (A): In SQL, INSERT INTO is a Data Definition Language (DDL) Command. 2025
5 Reason (R): DDL commands are used to create, modify, or remove database structures, such SQP
as tables.
3 What will be the output of the following SQL command? SELECT MONTHNAME('2024-08- 2025
6 02');
(A) 08 (B) 02 (C) February (D) August
4 With respect to SQL, match the function given in column-II with categories given in column- 2025
0 I:
I II
Math function (a) COUNT()
i)
(ii) Aggregate function (b) ROUND()
(iii) Date function (c) RIGHT()
(iv) Text function (d) YEAR()
Options:
(A) (i)-(c), (ii)-(d), (iii)-(a), (iv)-(b) (B) (i)-(b), (ii)-(a), (iii)-(d), (iv)-(c)
(C) (i)-(d), (ii)-(b), (iii)-(a), (iv)-(c) (D) (i)-(b), (ii)-(a), (iii)-(d), (iv)-(c)
4 Assertion (A): The ROUND() function in SQL can be used to round off a number to a 2025
1 specified number of decimal places.
Reason (R): The ROUND() function is a string function that accepts character values as input
and returns numerical values as output.
5 Write commands in SQL for (i) to (iv) and output for (v) and (vi). 202
Table : Store 0
SQP
StoreId Name Location City NoOfEmp DateOpen SalesAmt
S101 Planet Fashion Bandra Mumbai 7 2015-10-16 40000
S102 Vogue Karol Bagh Delhi 8 2015-07-14 120000
S103 Trends Powai Mumbai 10 2015-06-24 30000
S104 Super Fashion Thane Mumbai 11 2015-02-06 45000
S105 Annabelle South Extn. Delhi 8 2015-04-09 60000
S106 Rage Defence Colony Delhi 5 2015-03-01 20000
(i) To display names of stores along with SalesAmount of those stores that have ‘fashion’
anywhere in their store names.
(ii) To display Stores names, Location and DateOfOpen of stores that were opened before 1st
March, 2015.
(iii) To display name and location of those store which have either ‘u’ as second character in
their name.
(iv) To display the City and the number of stores located in that City, only if number of stores
is more than 2.
(v) To display names of stores along with Sales Amount of those stores that are located in
Mumbai.
(vi) To display the details of store in alphabetical order of name.
(vii) Select Min(DateOpen) from Store;
(viii) Select Count(Storeid), Noofemp From Store Group By Noofemp Having
Max(Salesamt)<60000;
1 Consider the following SQL string: "Preoccupied". Write commands to display: 202
4 a. "occupied" b. "cup" 1
SQP
1 Considering the same string “Preoccupied”. Write SQL commands to display: 202
5 a. the position of the substring ‘cup’ in the string “Preoccupied” 1
SQP
b. the first 4 letters of the string
1 Write the SQL functions which will perform the following operations: 202
8 i) To display the name of the month of the current date. 1
SQP
ii) To remove spaces from the beginning and end of a string, "Panorama ".
iii) To display the name of the day eg, Friday or Sunday from your date of birth, dob.
iv) To display the starting position of your first name (fname) from your whole name (name).
v) To compute the remainder of division between two numbers, n1 and n2
2 Mr. Som, a HR Manager in a multinational company “Star-X world” has created the following 2021-
22
3 table to store the records of employees: Term
Table: Emp 2 SQP
2 [Link] is working on a MySQL table named ‘Hotel’ having following structure: 2021-
22
4 Field Type Null Key Default Extra Term
user_id varchar(20) YES NULL 2 SQP
name varchar(20) YES NULL
city varchar(20) YES NULL
mobile_no varchar(11) YES NULL
She need to perform following task on the table:
i. To fetch last 2 characters from the user_id column.
ii. To display the values of name column in lower case.
iii. To display 3 characters from 3rd place from the column city.
Suggest suitable SQL function for the same. Also write the query to achieve the desired task.
2 While dealing with string data type in MySQL, its observed that sometimes unnecessary space 2021-
22
7 character comes in between which hampers the successful execution of a string manipulation Term
module. Name the suitable MySQL function (s) to remove leading, trailing and both type of 2 SQP
space characters from a string. Also give MySQL queries to depict the same.
1 Keyboard IO 15 450
2 Mouse IO 10 350
3 Wifi-router NW 5 2600
4 Switch NW 3 3000
5 Monitor O 10 4500
6 Printer O 4 17000
Write SQL queries for the following:
(a) To display the records in decreasing order of price.
(b) To display category and category wise total quantities of products.
(c) To display the category and its average price.
(d) To display category and category wise highest price of the products.
2 Give any two differences between the POWER() and SUM() SQL functions. 2021-22
Term 2
5 Ms. Mohini is working in a school and stores the details of all students in a table 2021-22
Term 2
SCHOOLDATA.
TABLE: SCHOOLDATA
Admno Name Class House Percent Gender Dob
20150001 Aditya Das 10 Green 86 Male 2006-02-20
20140212 Harsh Sharma 11 Red 75 Male 2004-10-05
20090234 Swapnil Pant 10 Yellow 84 Female 2005-11-21
20130216 Soumen Rao 9 Red 91 Male 2006-04-10
20190227 Rahil Arora 10 Blue 70 Male 2005-05-14
20120200 Akasha Singh 11 Red 64 Female 2004-12-16
A) Write SQL statements from the above given table to:
i) To remove leading spaces from the column Name.
ii) Display the names of students who were born on Sunday.
B) Predict the output of the following SQL queries from the given table: SCHOOLDATA
i) SELECT MAX(Percent) from SCHOOLDATA;
ii) SELECT LEFT(Gender,1), Name from SCHOOLDATA WHERE YEAR(Dob)=2005;
8 Write the names of SQL functions to perform the following operations: 2021-22
Term 2
i) Display name of the Month from your date of birth.
ii) Convert email-id to lowercase.
iii) Count the number of characters in your name.
1 Rashmi, a database administrator needs to display house wise total number of records of 2023
2 ‘Red’ and ‘Yellow’ house. She is encountering an error while executing the following query: SQP
SELECT HOUSE, COUNT (*) FROM STUDENT GROUP BY HOUSE WHERE HOUSE=’RED’ OR
HOUSE= ‘YELLOW’;
Help her in identifying the reason of the error and write the correct query by suggesting the
possible correction (s).
1 What is the purpose of Order By clause in SQL? Explain with the help of suitable example. 2023
3 SQP
1 Write outputs for SQL queries (i) to (iii) which are based on the given table PURCHASE: 2023
4 TABLE: PURCHASE SQP
CNO CNAME CITY QUANTITY DOP
C01 GURPREET NEW DELHI 150 2022-06-11
C02 MALIKA HYDERABAD 10 2022-02-19
C03 NADAR DALHOUSIE 100 2021-12-04
C04 SAHIB CHANDIGARH 50 2021-10-10
C05 MEHAK CHANDIGARH 15 2021-10-20
i. SELECT LENGTH(CNAME) FROM PURCHASE WHERE QUANTITY>100;
ii. SELECT CNAME FROM PURCHASE WHERE MONTH(DOP)=3;
iii. SELECT MOD (QUANTITY, DAY(DOP)) FROM PURCHASE WHERE CITY= ‘CHANDIGARH’;
1 Based on table STUDENT given here, write suitable SQL queries for the following: 2023
5 Roll No Name Class Gender City Marks SQP
1 Abhishek XI M Agra 430
2 Prateek XII M Mumbai 440
3 Sneha XI F Agra 470
4 Nancy XII F Mumbai 492
5 Himanshu XII M Delhi 360
6 Anchal XI F Dubai 256
7 Mehar X F Moscow 324
8 Nishant X M Moscow 429
i. Display gender wise highest marks.
ii. Display city wise lowest marks.
iii. Display total number of male and female students.
1 Discuss the significance of Group by clause in detail with the help of suitable example. 2023
6 SQP
1 Write suitable SQL query for the following: 2023
7 i. Display 7 characters extracted from 7th left character onwards from the string ‘INDIA SQP
SHINING’.
ii. Display the position of occurrence of string ‘COME’ in the string ‘WELCOME WORLD’.
iii. Round off the value 23.78 to one decimal place.
iv. Display the remainder of 100 divided by 9.
v. Remove all the expected leading and trailing spaces from a column userid of the table
‘USERS’.
1 Differentiate between COUNT( ) and COUNT(*) functions in MYSQL. Give suitable examples 2023
9 to support your answer. SQP
2 Shreya, a database administrator has designed a database for a clothing shop. Help her by 2023
0 writing answers of the following questions based on the given table:
TABLE: CLOTH
CCODE CNAME SIZE COLOR PRICE DOP
C001 JEANS XL BLUE 990 2022-01-21
C002 T SHIRT M RED 599 2021-12-12
C003 TROUSER M GREY 399 2021-11-10
C004 SAREE FREE GREEN 1299 2019-11-12
C005 KURTI L WHITE 399 2021-12-07
i. Write a query to display cloth names in lower case.
ii. Write a query to display the lowest price of the cloths.
iii. Write a query to count total number of cloths purchased of medium size.
iv. Write a query to count year wise total number of cloths purchased.
2 Keshav has written the following query to find out the sum of bonus earned by the 2023
1 employees of WEST zone :
SELECT zone, TOTAL (bonus) FROM employee HAVING zone = 'WEST';
But he got an error. Identify the errors and rewrite the query by underlining the
correction(s) done.
2 Consider the table Patient given below and write SQL commands. 2023
2 Table: Patient
Patientid Name City Phone Dateofadm Department
1000001 Ritvik Garg Delhi 68476213 2021-12-10 Surgery
1000002 Rahil Arora Mumbai 36546321 2022-01-08 Medicine
1000003 Mehak Bhatt Delhi 68721879 2022-02-02 Cardiology
1000004 Soumik Rao Delhi 26543266 2022-01-11 Medicine
1000005 Suresh Sood Bangalore 65432442 2021-03-09 Surgery
(i) Display the details of all patients who were admitted in January.
(ii) Count the total number of patients from Delhi.
(iii) Display the last 2 digits of the Patientid of all patients from Surgery Department.
2 Write the output (i-iii) for the following SQL commands. 2023
3 Table: FASHION
ID Product Price Qty
F01 Kajal 970 10
F02 Foundation 2100 15
F03 Night Cream 1700 20
F04 Day Cream 1400 10
F05 Shampoo 1200 25
F06 Lipstick 850 32
(i) SELECT COUNT(Product) FROM FASHION;
(ii) SELECT SUM (Price*Qty) FROM FASHION WHERE Product="Night Cream";
(iii) SELECT LEFT (Product, 4) FROM FASHION WHERE Price>1500;
Find the output of the following SQL queries :
(i) SELECT SUBSTR("CLIMATE CHANGE",4,4);
(ii) SELECT UCASE(RIGHT("Pollution",3));
(iii) SELECT LENGTH("HAPPY")+3;
2 Write the SQL queries which will perform the following operations: 2023
4 (i) To display the year from your Date of Admission which is '2023-05-15'.
(ii) To convert your email id 'ABC@[Link]' to lowercase.
(iii) To remove leading spaces from a string 'my country'.
(iv) To display current date.
(v) To display the value of 106
3 Consider the given SQL string: "12#All the Best!". Write suitable SQL queries for the 202
following: 4
SQP
i. Returns the position of the first occurrence of the substring “the” in the given string.
ii. To extract last five characters from the string.
4 Based on the SQL table CAR_SALES, write suitable queries for the following: 202
NUMBER SEGMENT FUEL QT1 QT2 4
SQP
1 Compact HatchBack Petrol 56000 70000
2 Compact HatchBack Diesel 34000 40000
3 MUV Petrol 33000 35000
4 MUV Diesel 14000 15000
5 SUV Petrol 27000 54000
6 SUV Diesel 18000 30000
7 Sedan Petrol 8000 10000
8 Sedan Diesel 1000 5000
i. Display fuel wise average sales in the first quarter.
ii. Display segment wise highest sales in the second quarter.
iii. Display the records in the descending order of sales in the second quarter. OR Predict the
output of the following queries based on the table CAR_SALES given above:
i. SELECT LEFT(SEGMENT,2) FROM CAR_SALES WHERE FUEL= "PETROL";
ii. SELECT (QT2-QT1)/2 "AVG SALE" FROM CAR_SALES WHERE SEGMENT= "SUV";
iii. SELECT SUM(QT1) "TOT SALE" FROM CAR_SALES WHERE FUEL= "DIESEL";
7 Preeti manages database in a blockchain start-up. For business purposes, she created a table 202
named BLOCKCHAIN. Assist her by writing the following queries: 4
SQP
TABLE: BLOCKCHAIN
id user value hash transaction_date
1 Steve 900 ERTYU 2020-09-19
2 Meesha 145 @345r 2021-03-23
3 Nimisha 567 #wert5 2020-05-06
4 Pihu 678 %rtyu 2022-07-13
5 Kopal 768 rrt4% 2021-05-15
7 Palakshi 534 wer@3 2022-11-29
i. Write a query to display the year of oldest transaction.
ii. Write a query to display the month of most recent transaction.
iii. Write a query to display all the transactions done in the month of May.
iv. Write a query to count total number of transactions in the year 2022.
1 (a) Consider the given table and write the following queries in MySQL : 202
0 Table: Sports 4
Sid SName Fees DateofPlay CoachId
1 Karate 1200 2024-08-24 S1
2 Football 1800 2024-09-13 S2
3 Cricket 1500 2024-06-14 S3
4 Lawn Tennis 2500 2024-09-25 S4
5 Badminton 1800 2024-10-20 S5
(i) To display Sid and name of those sports which are to be played in the month of September.
(ii) To display all Sports names in lower case.
(iii) To display last two characters of all sports names whose fees is less than 1500.
(b) Predict the output of the following queries based on the table Sports given above:
(i) SELECT UCASE(TRIM(SName)) FROM Sports WHERE Sid=5 ;
(ii) SELECT LEFT (SName,3) FROM Sports WHERE DateofPlay>"2024-09-13";
(iii) SELECT SUBSTR (CoachId,1) FROM Sports WHERE SName="Cricket" or Fees>=2000;
1 Write any two differences between UPDATE and ALTER TABLE commands of MySQL. 202
2 4
1 Answer the following questions based on the table Salesman given below : 202
3 Table: Salesman 4
salesman_id name city commission
5001 Neil Bhatt Delhi 0.15
5002 Rohan Malik Mumbai 0.13
5005 Ravi Mohan Delhi 0.11
5006 Mehak Rai Delhi 0.14
5007 Paul Lal Bangalore 0.13
5003 Raman Sen Kolkata 0.12
(i) How many tuples does the given table have?
(ii) Suggest the primary key for the given table.
(iii) Write the MySQL query to display all the records in descending order of commission.
1 Excellent Consultancy Pvt. Ltd. maintains two tables for all its employees. 202
4 Table: Employee 4
Employee_ id First_ name Last_ name Salary Joining_date Department
El0l Monika Das 100000 2019-01-20 Finance
E102 Mehek Verma 600000 2019-01-15 IT
E103 Manan Pant 890000 2019-02-05 Banking
E104 Shivam Agarwal 200000 2019-02-25 Insurance
E105 Alisha Singh 220000 2019-02-28 Finance
E106 Poonam Sharma 400000 2019-05-10 IT
E107 Anshuman Mishra 123000 2019-06-20 Banking
Table: Reward
Employee_id Date_reward Amount
E101 2019-05-11 1000
E102 2019-02-15 5000
E103 2019-04-22 2000
E106 2019-06-20 8000
A) Write suitable SQL queries to perform the following task :
(i) Change the Department of Shivam to IT in the table Employee.
(ii) Remove the record of Alisha from the table Employee.
(iii) Add a new column Experience of integer type in the table Employee.
(iv) Display the first name, last name and amount of reward for all employees from the tables
Employee and Reward.
(v) Display first name and salary of all the employees whose amount is less than 2000 from
the tables Employee and Reward.
B) Write suitable SQL queries for the following task:
(i) Display the year of joining of all the employees from the table Employee.
(ii) Display each department name and its corresponding average salary.
(iii) Display the first name and date of reward of those employees who joined on Monday
from the tables Employee and Reward.
(iv) Display sum of salary of those employees whose reward amount is greater than 3000
from the tables Employee and Reward.
(v) Remove the table Reward.
1 Rupam created a MySQL table to store the details of Nobel prize winners. Help her to write 202
5 the following MySQL queries: 4
Table: NOBEL
Winner_id YEAR SUBJECT WINNER COUNTRY CATEGORY
1001 1970 Physics Hannes Alfven Sweden Scientist
1002 1970 Physiology Bernard Katz NULL Scientist
1003 1970 Literature Aleksandr Solzhenitsyn Russia Linguist
1004 1971 Chemistry Gerhard Herzberg Germany Scientist
1005 1978 Peace Menachem Begin Israel Prime Minister
1006 1987 Economics Robert Solow USA Economist
1007 1994 Literature Kenzaburo Oe Japan Linguist
(i) Display the names of Nobel Prize winner in 'Literature’ for the year 1970.
(ii) Display the subject and category of winners whose country is not known.
(iii) Display the details of all Nobel Prize winners who were Scientists.
(iv) Count total number of winners whose subject is Literature.
1 Consider the string: "Database Management System". Write suitable SQL queries for the 202
6 following: 5
SQP
I. To extract and display "Manage" from the string.
II. Display the position of the first occurrence of "base" in the given string.
1 Define the term Primary Key in a database. Explain how it is different from a Candidate Key. 202
7 5
SQP
1 I. Write an SQL statement to create a table named STUDENTS, with the following 202
8 specifications: 5
SQP
Column Name Data Type Key
StudentID Numeric Primary Key
FirstName Varchar(20)
LastName Varchar(10)
DateOfBirth Date
Percentage Float(10,2)
II. Write SQL Query to insert the following data in the Students Table
1, Supriya, Singh, 2010-08-18, 75.5
1 Write the SQL statement to create a table, Customer with the following specifications: 202
0 Table: Customer 5
Column Name Data Type Key
CID Int Primary Key
FName Varchar(20)
LName Varchar(20)
Age Int
(ii) Write the SQL query to display all records in descending order of LName from the Table
Customer.
1 An educational institution is maintaining a database for storing the details of courses being 202
1 offered. The database includes a table COURSE with the following attributes: 5
C_ID: Stores the unique ID for each course.
C_NAME: Stores the course's name.
INSTRUCTOR: Stores the name of the course instructor.
DURATION: Stores the duration of the course in hours.
Table: COURSE
C_ID C_NAME INSTRUCTOR DURATION
C101 Data Structures Dr. Alok 40
C102 Machine Learning Prof. Sunita 60
C103 Web Development Ms. Sakshi 45
C104 Database Management Mr. Suresh 50
C105 Python Programming Dr. Pawan 35
Write SQL queries for the following:
(i) To add a new record with following specifications:
C_ID: C106, C_NAME: Introduction to AI, INSTRUCTOR: Ms. Preeti, DURATION: 55
(ii) To display the longest duration among all courses.
(iii) To count total number of courses run by the institution.
(iv) To display the instructors’ name in lower case.
1 Ashutosh, who is a manager, has created a database to manage employee records. The 202
2 database includes a table named EMPLOYEE whose attribute names are mentioned below: 5
EID: Stores the unique ID for each employee.
EMP_NAME: Stores the name of the employee.
DEPT: Stores the department of the employee.
SALARY: Stores the salary of the employee.
JOIN_DATE: Stores the employee’s joining date.
Table: EMPLOYEE
EID EMP_NAME DEPT SALARY JOIN_DATE
E01 ARJUN SINGH SALES 75000 2019-11-01
E02 PRIYA JAIN ENGINEERING 65000 2020-06-20
E03 RAVI SHARMA MARKETING 60000 2021-08-16
E04 AYESHA NULL 40000 2021-01-05
E05 RAHUL VERMA FINANCE 90000 2017-06-21
Write the output of the following SQL Queries:
(i) Select SUBSTRING(EMP_NAME, 1, 5) from EMPLOYEE where DEPT = 'ENGINEERING';
(ii) Select EMP_NAME from EMPLOYEE where month(JOIN_DATE) = 8;
(iii) Select EMP_NAME from EMPLOYEE where SALARY > 60000;
(iv) Select count(DEPT) from EMPLOYEE;
1 Write SQL query for the following: 202
3 (i) To display sum total of all the values of the Score column, from STUDENTS table. 5
(ii) To display the first five characters of the Name column from STUDENTS table.
(iii) To display the values of Name column from the STUDENTS table, after removing the
trailing spaces.
(iv) To retrieve the lowest score from the Score column of GRADES table.
(v) To increase the fee of all students by 100, in the STUDENTS table. (The name of the
column is FEE).
1 Write SQL queries for the following: 202
4 (i) To calculate the square of 15. 5
(ii) To round the number 456.789 to the nearest integer.
(iii) To display the position of first occurance of 'com' in the string '[Link]'.
(iv) To display the name of the day for the date '2024-11-07'.
(v) To display the current date and time.
1 Assume that you are working in the IT Department of a Creative Art Gallery (CAG), which sells 202
5 different forms of art creations like Paintings, Sculptures, etc. The data of Art Creations and 5
Artists are kept in tables Articles and Artists respectively. Following are few records from
these two tables:
Table: Articles
Code A_Code Article DOC Price
PL001 A0001 Painting 2018-10-19 20000
SC028 A0004 Sculpture 2021-01-15 16000
QL005 A0003 Quilling 2024-04-24 3000
Table: Artists
A_Cod Name Phone Email DOB
e
A0001 Roy 595923 r@[Link] 1986-10-12
A0002 Ghosh 1122334 ghosh@[Link] 1972-02-05
A0003 Gargi 121212 Gargi@[Link] 1996-03-22
A0004 Mustafa 33333333 Mf@[Link] 2000-01-01
Note:
The tables contain many more records than shown here.
DOC is Date of Creation of an Article.
As an employee of CAG, you are required to write the SQL queries for the following:
(i) To display all the records from the Articles table in descending order of price.
(ii) To display the details of Articles which were created in the year 2020.
(iii) To display the structure of Artists table.
(iv) To display the name of all artists whose Article is Painting through Equi Join.
Saman has been entrusted with the management of Law University Database. He needs to
access some information from FACULTY and COURSES tables for a survey analysis. Help him
extract the following information by writing the desired SQL queries as mentioned below.
Table: FACULTY Table: COURSES
F_I FName LName Hire_Date Salary C_I F_ID CName Fees
D D
102 Amit Mishra 12-10- 12000 C21 102 Grid Computing 40000
1998 C22 106 System Design 16000
103 Nitin Vyas 24-12- 8000 C23 104 Computer Security 8000
1994 C24 106 Human Biology 15000
104 Rakshit Soni 18-5-2001 14000 C25 102 Computer Network 20000
105 Rashmi Malhotra 11-9-2004 11000 C26 105 Visual Basic 6000
106 Sulekha Srivastava 5-6-2006 10000
(I) To display complete details (from both the tables) of those Faculties whose salary is less
than 12000.
(II) To display the details of courses whose fees is in the range of 20000 to 50000 (both
values included).
(III) To increase the fees of all courses by 500 which have "Computer" in their Course names.
(IV) To display names (FName and LName) of faculty taking System Design.
(V) To display the Cartesian Product of these two tables.