SQL Questions Answers
SQL Questions Answers
Create a student table with the student id, name, class, date of birth,
section and marks as attributes where the student id is the primary key.
Ans.
Ans.
Q3. Delete the details of a particular student whose id is 5, from the above
table.
Ans.
Q4. Use the select command to get the details of the students with marks
more than 80.
Ans.
Ans.
Q6. Display students’ details of all students who are born in the year 2000.
Ans.
Q7. Display students’ names, class, section who are born in month of ‘June’,
also sort them in the descending order of class, within same their names
should display in alphabetical order.
Ans.
Q8. Display student id, name and percentage (assuming marks are out of
40).
Ans.
Ans.
UPDATE student SET marks = marks + (marks * 2 / 100);
Q10. Add one more column in the above table result, storing values ‘P’ for
pass and ‘F’ for fail.
Ans.
Q11. Write SQL commands to create above tables with foreign keys and
primary keys in tables mentioned below:
Order: (order ID (PK), cust_ id (FK), product id (FK) and order Date) by
joining two tables Product: (product id (PK), description, quantity, unit
price) and Customer: (customer ID (PK), customer Name, contact No,
country).
Ans.
Q12. Display order ID, customer Name, and order Date by joining two
tables Order and Customer.
Ans.
Q13. Find the total number of customers from each country along with
country name.
Ans.
Q14. Display order id, customer name, description and unit price of all
orders.
Ans.
Q15. Display order date, customer name, unit price for all orders which are
placed after 01-01-2020 in reverse chronological order of order date.
Ans.
Q16. Display order id and description of products all products ordered from
“India”.
Ans.
Q17. Display no of customers from “India” who had placed the order before
06-01-2020.
Ans.
Q18. Display total sale made for each product along with description of
products.
Ans.
SELECT product_id, description, SUM(unit_price * quantity) AS total_sale
FROM Product, Order
WHERE Product.product_id = Order.product_id
GROUP BY product_id, description;
Q19. Display order id, product id, unit price and order date of all orders
whose unit price is greater than unit price of product “P01”.
Ans.
Q20. Display structure of all tables (Order, Product, and Customer) along
with their constraints.
Ans.
DESCRIBE Order;
DESCRIBE Product;
DESCRIBE Customer;