ASSESSEMENTS SQL - Batch 10
ASSESSEMENTS SQL - Batch 10
ASSESSEMENTS SQL - Batch 10
DATE: 09/May/2023
BATCH 10
ASSESSMENT 1
1. Write a query to create the table with the below-mentioned fields in SQL. Where the
First_name ,DOB,Honour_subject shouldn’t allow any Null value.
Create table samp(First_name varchar(20) not null, DOB date not null,
Honour_subject varchar(20) not null)
2. Write a query to insert 10 random data into the student table. With DOB Ranging
from 1/Jan1995 to 31/Dec/1999 and Student marks from 1 to 100
3. Write a Query to pick students who Don’t have a Last name
UNION:
Union is simply joining two or more data sets into a single set. This is used to combine
two queries into a single result set using the select statements. Union extracts all the rows
that are described in the query.
UNION ALL:
Column count in all tables must be the same. The data types of columns must be the same.
The columns must be in the same order in each table.
5. Write a Query to Pick find average and total mark scored by each Honor subject.
6. Write a Query to Pick students whose First name contains at least of 5 characters
and second last character is ‘a’
9. Write a Query to add gender column and insert a value into the column.
14. Write the Query to pick Honor subject by highest of average Score grouped across
honor subject.
SELECT TOP 1 HONUR_SUBJECT, AVG(STU_MARKS) FROM STUDENT GROUP BY
HONOUR_SUBJECT ORDER BY AVG(STU_MARKS) DESC
SQL ASSESSMENT 2
DATE: 13-05-2023
BATCH 10
1. How can you select all the even number records from a table?
2. As like ‘TOP n’ Clause, write a query to Pick the Bottom 5 records from practice Employee Table.
3. Write a SQL query to find the 3th highest employee salary from an employee table by each
department.
SELECT department, max(salary) as '3rd highest salary' FROM Employee WHERE salary < (SELECT
max(salary) FROM employee WHERE department=department) GROUP BY department HAVING
Count(salary) >= 3;
4. With this below table, write a query to delete the duplicate records. e.g. (first and last row are
duplicated)
DELETE FROM test WHERE column_A IN ( SELECT column_A FROM test GROUP BY column_A,
column_B HAVING COUNT(*) > 1
5. With the result from above table write a query to update column A as inverse of Column B as
like example.
Write a Query to de-normalize this tables, and pick only columns as below and filter only rows
where student name starts with any character between ‘a’ and ‘h’ and may follow by any
characters.
output
7. Create this below table Write a Query to count the son or daughter for each parent.
8. From the same Family table pick the grand parent of Sonu.
Write a Query to pick customer complete name whose total purchase was higher than
average purchases of whole customers.
Select concat(c.firstname, ' ', c.lastname) as fullname, sum(o.totalamount) as
totalpurchaseamount from customers c join orders o on c.customerid = o.customerid
Group by c.customerid, c.firstname, c.lastname having sum(o.totalamount) > ( select
avg(totalamount) from orders
)
Output:
Write a Query to pick days by which temperature was higher than the previous day.
Select t1.recorddate, t1.temperature as presentday_temperature, t2.temperature as
Lastday_temperature from temperaturedata t1 join temperaturedata t2 on t1.id = t2.id + 1 where
t1.temperature > t2.temperature;
Output:
4. Write a SQL query to find the percentage of males and females. Print the output to the
nearest integer.
INPUT: Gender
Gender
Male
Male
Male
Female
Male
Female
OUTPUT:
Male% Female%
67 33
Select gender, round(count(*) * 100.0 / (select count(*) from test), 0) as percentage from test
group by gender;
5. Use the practise Employee table and create the below table
Classify all employees based on the total payout without using case- when..
OUTPUT: