SQL Lab
SQL Lab
Lab Task1
Create the following table
CREATE TABLE writer (
poet varchar(50) default NULL,
anthology varchar(40) default NULL,
copies_in_stock int null
default NULL
);
Task 2
Insert the following values
4. SELECT poet,
MAX(copies_in_stock) max,
MIN(copies_in_stock) min,
AVG(copies_in_stock) avg,
SUM(copies_in_stock) sum
FROM writer GROUP BY poet;
5. SELECT poet,
MAX(copies_in_stock) AS max,
MIN(copies_in_stock) AS min,
AVG(copies_in_stock) AS avg,
SUM(copies_in_stock) AS sum
FROM writer WHERE copies_in_stock > 5 GROUP BY poet;
6. SELECT poet,
MAX(copies_in_stock) AS max,
MIN(copies_in_stock) AS min,
AVG(copies_in_stock) AS avg,
SUM(copies_in_stock) AS sum
FROM writer GROUP BY poet HAVING (copies_in_stock) > 5;
CORRECT QUERY:
SELECT poet,
MAX(copies_in_stock) AS max,
MIN(copies_in_stock) AS min,
AVG(copies_in_stock) AS avg,
SUM(copies_in_stock) AS sum
FROM writer GROUP BY poet,(copies_in_stock) HAVING (copies_in_stock) > 5;
7. SELECT MAX(copies_in_stock)
FROM writer
GROUP BY poet
HAVING COUNT(copies_in_stock) > 1;
8. SELECT poet,
MAX(copies_in_stock) AS max,
MIN(copies_in_stock) AS min,
AVG(copies_in_stock) AS avg,
SUM(copies_in_stock) AS sum
FROM writer GROUP BY poet HAVING poet > 'E';
Task 4
If you have the Northwind database you can see that it has several views installed
bydefault.
The view "Current Product List" lists all active products (products
that are not Discontinued) from the "Products" table.
We can also add a condition to the query. Now we want to see the total sale only for the
category "Beverages":
Task 5
Write a short note on this lecture. What did you learn?
We learned about SQL views, which are virtual tables created from SELECT queries. The
examples using the Northwind database showed how views can simplify complex queries and
enhance data organization. Views are valuable tools for managing and analyzing data in
relational databases.
Max Obtained
Task Comments(if any)
Marks Marks
1. 5
2. 5
3. 5
4. 5
5. 5
Total 25 Signature
Note : Attempt all tasks and get them checked by your Lab. Instructor