Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
80 views

SQL Revision

Uploaded by

Rajitha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
80 views

SQL Revision

Uploaded by

Rajitha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Page |1

REVISION SHEET – NOVEMBER 2024


INFORMATICS PRACTICES
1) Gopi Krishna is using a table Employee .it has the following Columns:
Code, Name, Salary, Deptcode
SELECT Deptcode, MAX(Salary) FROM Employee;
He wants to display maximum salary for each department. But he did not get the desired result.
Rewrite the above query with necessary change to help him get the desired result.

2) What is NULL ? How it is different from Zero ? How are NULL values treated by aggregate functions?

3) Consider a table “Salesman” with the following data:

Table : Salesman

Write SQL queries using SQL functions to perform the following operations.
(i) Display salesman name and bonus after rounding off to zero decimal places.
(ii) Display the month name for the date of join of salesman.
(iii) Display the minimum salary of the Salesman.

4) What is the purpose of GROUP BY clause in MySQL? How is it different from ORDER BY clause?
5) Write SQL commands for the statements (i) to (iii) which are based on the given table PERSON
Page |2

6) Naveen, a database administrator has designed a database for a Computer Stock. Help her by
writing answers of the following questions based on the given table:
TABLE: Stock

i. Write a query to display product name in upper case.


ii. To display the records in descending order of the price.
iii. To display category and category wise highest price of product.
IV. To display the total quantity of all products.

7) Write suitable SQL query for the following:


i. Display 7 characters extracted from 7th left character onwards from the string ‘INDIA SHINING’.
ii. Display the position of occurrence of string ‘COME’ in the string ‘WELCOME WORLD’.
iii. Round off the value 78.779 to 2nd decimal place.
iv. Display the remainder of 149 divided by 6.
v. Remove all the expected leading and trailing spaces from a column userid of the table ‘USERS’ and
convert to lowercase.

8) Explain the following SQL functions using suitable examples.


i. LENGTH()
ii. TRIM()
iii. NOW()
iv. DAYNAME()
v. POWER()

9) Consider the given SQL string:


“Informatics Practices Exam”
Write suitable SQL queries for the following:
i. Returns the position of the first occurrence of the substring “mat” in the given string.
ii. To extract last six characters from the string

10) Briefly explain the purpose of the following: i. power() ii. mod()
Page |3

11) Based on the SQL table EXAM, write suitable queries for the following:

i. To display all information of the students of Commerce in descending order of


percentage
ii. To display Adno, SName, Percentage of those students whose name is less than 6
characters long.
iii. To insert a new row in the table EXAM (1005,’Ananya’,65.5,’12B’,’Commerce’)

Predict the output of the following queries based on the table EXAM given above:
i. SELECT COUNT * FROM EXAM;
ii. SELECT SName, Percentage FROM EXAM WHERE Name LIKE “N%”;
iii. SELECT ROUND (Percentage, 0) FROM EXAM WHERE Adno = “1004”;

12) Predict the output of the following SQL queries


i. SELECT TRIM (“ ALL THE BEST “);
ii. SELECT LEFT(‘INFORMATICS’,6);
iii. SELECT UPPER(MID(“START UP INDIA”,10));

13) Vijay manages a database with the latest price of Electronic Devices. He created a table named
DEVICES. Assist him by writing the following Queries:

i. To display the records in decreasing order of Price.


ii. To display category and category wise total quantities of products.
iii. To display the category and its average Price.
iv. To display category and category wise highest price of the products.

14) Write suitable SQL queries for the following:


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
iv. To remove leading spaces from the ‘ VANDE BHARAT ‘.
v. Display the string ‘CHEST’ from the string ‘MANCHESTER UNITED’
Page |4

15) Anya has created following table named exam

Help him in writing SQL queries to perform the following task:


i. Insert a new record in the table having following values: [6,’Aarav’,’CS’,65]
ii. To change the value “IP” to “Informatics Practices” in subject column.
iii. To remove the records of those students whose marks are less than 40
iv. To add a new column Grade of suitable datatype.
v. To display records of “ Computer Science” subject

16)
Consider “Winners never quit”. Write the queries for the following tasks.
i. Write a command to display “quit”.
ii. Write a command to check the first occurrence of letter ‘n’

17) Basedontable Employee given here, write suitable SQL queries for the following:

i. Display gender wise average salary.


ii. Display designation wise maximum salary.
iii. Display total number of employees in each Dept.

Predict the output of the following queries based on the above table Employee:
i. SELECT LEFT (Name , 2) FROM Employee WHERE Gender = “F”;
ii. SELECT AVG(Salary) FROM Employee WHERE Dept = “Sales”;
iii. SELECT SUM(Salary) FROM Employee WHERE Designation = “Clerk”;
Page |5

18) Write MySQL statements for the following:


i. To create a database named AUTOMOBILE.
ii. To create a table named VEHICLE based on the following specification:

19) Consider the Table CLUB given below:

Answer the followings based on the above mysql table ‘CLUB’


i. Write SQL query to display the average pay for karate coach
ii. Write sql query to display month for date of appointment DATEOFAPP
iii. Write sql query to display the details of male coach in ascending order of their age
iv. Write SQL query to display game wise maximum pay of all coaches.

20) Write suitable SQL query for the following:


i. Display 7 characters extracted from 7th left character onwards from the string ‘INDIA SHINING’.
ii. Display the position of occurrence of string ‘COME’ in the string ‘WELCOME WORLD’.
iii. Round off the value 78.779 to 2 nd decimal place.
iv. Display the remainder of 149 divided by 6.
v. Remove all the expected leading and trailing spaces from a column userid of the table ‘USERS

21) Consider the following table TEACHER

Help her in writing SQL queries to the perform the following task:
a) Insert a new record in the table having following values:
[6,'Abhinav','office',12.10.2023]
Page |6

b) To change the value “CS” to “Computer Science” in subject column.


c) To remove the records of those teachers who belongs to physics department.
d) To add a new column Salary of suitable datatype.
e) To display records of “CS” department.

22) Consider the given MySQL query: SELECT NOW();


It returns the current Date and Time. Modify this query with help of suitable date functions to :
A. Return the month from the current date and time.
B. Retrieve the day of the week for the current date and time.

23) What is the difference between Aggregate Function and Scaler Function in MySQL? Provide the name
of one function from each.
24) Consider the SQL table "PRODUCT_SALES" with the following data:

Write suitable SQL queries for the following:


1. Display the region-wise average sales in the first quarter.
2. Display the segment-wise highest sales in the second quarter.
3. Display the records in descending order of sales in the second quarter.

Predict the output of the following queries based on the table


"PRODUCT_SALES" given above:
1. SELECT LEFT(Segment, 2) FROM PRODUCT_SALES WHERE Region = 'A';
2. SELECT (SalesQ2 - SalesQ1) / 2 AS Sale2 FROM PRODUCT_SALES WHERE Segment = 'High';
3. SELECT SUM(SalesQ1) AS "TOTAL” FROM PRODUCT_SALES WHERE Region = 'B';

25) Write MySQL statements for the following:


A. To use a database named Pets.
B. To see all the tables inside the database.
Page |7

C. To see the structure of the table named horse.

26) Niranjan is responsible for managing a database in a financial company. The company stores financial
transaction data in a table named FINE_TRNC. Niranjan needs your assistance in writing SQL queries to
retrieve specific information from the table. The attributes of the table are: TransactionDate,
TransactionAmount.
1. Write a query to display the date of the most recent transaction.
2. Write a query to retrieve the average transaction amount for the month of June.
3. Write a query to list the maximum amount for the transaction that occurred in the month of December.
4. Write a query to count the total number of transactions that took place in the year 2023.
27) Write suitable SQL queries for the following:
1. Write an SQL query to calculate 3 raised to the power of 4.
2. To round off the value 1969.5538 without any decimal part
3. Display the current date.
4. Convert the string 'After the test, take some rest’ to uppercase:
5. Return the length of the string 'To chaloshurukartehain'.

28) Take a look at the table structure of the table ‘IndianAlbums’ and `Artist_Info`

Write SQL queries to perform the following tasks:


1. Insert a new record into the `IndianAlbums` table with the following details:
Page |8

- AlbumName: "Lagaan"
- ReleaseYear: 2001
- Genre: "Soundtrack"
- Sales: 5000000
- Language: "Hindi"
2. Update the `IndianAlbums` table to modify the sales of the album with `AlbumID` 3 to 1000000.
3. Delete the record of the album named "Dil Se" from the `IndianAlbums` table.
4. Alter the table structure of `IndianAlbums` to add a new column named "Language" of data type
VARCHAR(50).
5. Select all albums released in the year 1990 or later, and for each album, retrieve the album name,
release year, genre, and the name of the artist.

29) In SQL, differentiate HAVING and WHERE clause?

30) Consider a table “AGENT” with the following data:

Write SQL query for the following:


(i) Display Agent name and bonus after rounding off to zero decimal places.
(ii) Display the month name of the date of join of all agents who have no bonus.
(iii) Display the minimum salary of all the agents

=========

You might also like