Computer Science
Consider the table ORDERS as given below
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.
A) Write the following queries:
(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) Display the sum of Price of all the orders for which the quantity is null.
OR
B) Write the output
(I) Select c_name, sum(quantity) as total_quantity from orders group by c_name;
(II) Select * from orders where product like '%phone%';
(III) Select o_id, c_name, product, quantity, price from orders where price between 1500 and 12000;
(IV) Select max(price) from orders;
SQL Queries
8 Likes
Answer
(A)
(I)
SELECT Product, SUM(Quantity)
FROM ORDERS
GROUP BY Product
HAVING SUM(Quantity) >= 5;
(II)
SELECT *
FROM ORDERS
ORDER BY Price DESC;
(III)
SELECT DISTINCT C_Name
FROM ORDERS;
(IV)
SELECT SUM(Price) AS Total_Price
FROM ORDERS
WHERE Quantity IS NULL;
OR
(B)
(I) Select c_name, sum(quantity) as total_quantity from orders group by c_name;
Output
+----------+----------------+
| c_name | total_quantity |
+----------+----------------+
| Jitendra | 1 |
| Mustafa | 2 |
| Dhwani | 1 |
+----------+----------------+
(II) Select * from orders where product like '%phone%';
Output
+------+---------+------------+----------+-------+
| O_Id | C_Name | Product | Quantity | Price |
+------+---------+------------+----------+-------+
| 1002 | Mustafa | Smartphone | 2 | 10000 |
| 1003 | Dhwani | Headphone | 1 | 1500 |
+------+---------+------------+----------+-------+
(III) Select o_id, c_name, product, quantity, price from orders where price between 1500 and 12000;
Output
+------+----------+------------+----------+-------+
| o_id | c_name | product | quantity | price |
+------+----------+------------+----------+-------+
| 1001 | Jitendra | Laptop | 1 | 12000 |
| 1002 | Mustafa | Smartphone | 2 | 10000 |
| 1003 | Dhwani | Headphone | 1 | 1500 |
+------+----------+------------+----------+-------+
(IV) Select max(price) from orders;
Output
+------------+
| max(price) |
+------------+
| 12000 |
+------------+
Answered By
7 Likes
Related Questions
Predict the output of the following code:
d = {"apple": 15, "banana": 7, "cherry": 9} str1 = "" for key in d: str1 = str1 + str(d[key]) + "@" + "\n" str2 = str1[:-1] print(str2)
Predict the output of the following code:
line = [4, 9, 12, 6, 20] for I in line: for j in range(1, I%5): print(j, '#', end="") print()
A csv file "Happiness.csv" contains the data of a survey. Each record of the file contains the following data:
- Name of a country
- Population of the country
- Sample Size (Number of persons who participated in the survey in that country)
- Happy (Number of persons who accepted that they were Happy)
For example, a sample record of the file may be:
[‘Signiland’, 5673000, 5000, 3426]
Write the following Python functions to perform the specified operations on this file:
(I) Read all the data from the file in the form of a list and display all those records for which the population is more than 5000000.
(II) Count the number of records in the file.
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
F_ID FName LName Hire_Date Salary 102 Amit Mishra 12-10-1998 12000 103 Nitin Vyas 24-12-1994 8000 104 Rakshit Soni 18-5-2001 14000 105 Rashmi Malhotra 11-9-2004 11000 106 Sulekha Srivastava 5-6-2006 10000 Table: COURSES
C_ID F_ID CName Fees C21 102 Grid Computing 40000 C22 106 System Design 16000 C23 104 Computer Security 8000 C24 106 Human Biology 15000 C25 102 Computer Network 20000 C26 105 Visual Basic 6000 (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)
(A) To display names (FName and LName) of faculty taking System Design.
OR
(B) To display the Cartesian Product of these two tables.