0% found this document useful (0 votes)
7 views3 pages

SQL Queries for Orders and Faculty Data

The document is an assignment for Class XII Computer Science for the academic year 2025-2026, focusing on SQL queries related to two tables: ORDERS and FACULTY/COURSES. It includes tasks such as displaying total quantities, sorting orders, deleting specific records, and extracting information for survey analysis. Additionally, it poses questions about the output of various SQL statements involving aggregation and joins between the tables.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

SQL Queries for Orders and Faculty Data

The document is an assignment for Class XII Computer Science for the academic year 2025-2026, focusing on SQL queries related to two tables: ORDERS and FACULTY/COURSES. It includes tasks such as displaying total quantities, sorting orders, deleting specific records, and extracting information for survey analysis. Additionally, it poses questions about the output of various SQL statements involving aggregation and joins between the tables.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CLASS: XII ASSIGNMENT (2025-2026) Subject: Computer Science

1. Consider the table ORDERS as given below, and write the following queries:
+------+----------+------------+----------+-------+------- +
| O_Id | C_Name | Product | Quantity | Price |
+------+----------+------------+----------+-------+------- +
| 1001 | Jitendra | Laptop | 1 | 12000 |
| 1002 | Mustafa | Smartphone | 2 | 10000 |
| 1003 | Dhwani | Headphone | 1 | 1500 |
|. |. |. |. |. |
+------+----------+------------+----------+-------+------- +

Note: The table contains many more records than shown here.
(i) To display the total Quantity for each Product, excluding Products with
total Quantity less than 5.
(ii) To display the orders table sorted by total price in descending order.
(iii) To display the distinct customer names from the Orders table.
(iv) To display the total number of orders quantity-wise.
(v) To delete all the orders where the Product is Laptop.
(vi) Display the sum of Price of all the orders for which the quantity is null.

2. 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.

1
(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.
3. Consider the following tables – FACULTY and COURSES :

What will be the output of the following statement?


(i) SELECT FID, MIN(FEES), MAX(FEES) FROM COURSES GROUP BY FID;
(ii) SELECT AVG(SALARY) FROM FACULTY WHERE FNAME LIKE '%a';

2
(iii) SELECT FNAME, CNAME FROM FACULTY F, COURSES C WHERE
[Link]=[Link] AND [Link]='F04';
(iv) SELECT FNAME, CNAME , FEES FROM FACULTY F , COURSES C
WHERE [Link] = [Link] AND FEE>15000;

Common questions

Powered by AI

The output of the query SELECT FID, MIN(Fees), MAX(Fees) FROM COURSES GROUP BY FID will show each unique FID paired with the minimum and maximum fees found in groups of courses sharing that FID. Grouping modifies aggregate functions to operate within these defined groups rather than across the entire table .

To display the total quantity for each product excluding those with a total quantity less than 5, you can use the SQL query: SELECT Product, SUM(Quantity) as TotalQuantity FROM ORDERS GROUP BY Product HAVING TotalQuantity >= 5. This query groups the table by Product, calculates the sum of Quantity for each group, and filters those groups where the sum is 5 or more .

To delete all orders where the Product is 'Laptop', use the command: DELETE FROM ORDERS WHERE Product='Laptop'. Specifying conditions when deleting data is crucial because it ensures that only the intended records are removed, preventing the accidental deletion of unrelated or important data .

To calculate the sum of prices where the quantity is null, use the SQL query: SELECT SUM(Price) FROM ORDERS WHERE Quantity IS NULL. The IS NULL condition checks for rows where the Quantity is null, and SUM aggregates the Price of these rows .

To display names of faculty teaching 'System Design', use the query: SELECT FName, LName FROM FACULTY F JOIN COURSES C ON F.FID=C.FID WHERE C.CourseName='System Design'. Joins are fundamental in SQL because they enable the combination of related data from multiple tables into a cohesive result set .

To retrieve distinct customer names from the 'ORDERS' table, use the query: SELECT DISTINCT C_Name FROM ORDERS. The DISTINCT keyword ensures that duplicate values are removed from the query results, allowing only unique entries to be displayed .

To display the 'ORDERS' table sorted by total price in descending order, use the query: SELECT * FROM ORDERS ORDER BY Price DESC. Sorting in SQL is achieved with the ORDER BY clause, which sorts the result set by one or more columns. By default, sorting is in ascending order; specifying DESC reverses this to descending order .

The Cartesian Product of two tables is obtained via the SQL query: SELECT * FROM FACULTY, COURSES, without a WHERE clause. This operation combines every row from the first table with every row from the second, resulting in a potentially very large result set. While useful for scenarios such as combinatorial analysis, it can be problematic due to its high computational cost and the generation of irrelevant results .

Saman can display course details with fees in the range of 20000 to 50000 using the query: SELECT * FROM COURSES WHERE Fees BETWEEN 20000 AND 50000. The BETWEEN operator is used for filtering within a specified range, including both boundary values .

To increase course fees by 500 for courses with 'Computer' in their names, use the query: UPDATE COURSES SET Fees = Fees + 500 WHERE CourseName LIKE '%Computer%'. This approach uses the LIKE operator to match patterns within strings, allowing targeted updates based on partial matches .

You might also like