-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathninth.sql
More file actions
87 lines (69 loc) · 2.81 KB
/
Copy pathninth.sql
File metadata and controls
87 lines (69 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
--1. Database and Table Creation
--Create a database named StoreDB and a table called Products with the following columns:
--ProductID (integer, primary key)
--ProductName (text)
--Price (decimal)
--QuantityInStock (integer)
create database StoreDB;
use StoreDB;
create table Products(
ProductID int primary key ,
ProductName text,
Price decimal,
QuantityInStock int
);
--2. Inserting Data into the Table
--Now, insert the following sample data into the Products table:
--ProductID: 1, ProductName: "Laptop", Price: 1200.50, QuantityInStock: 15
--ProductID: 2, ProductName: "Smartphone", Price: 800.00, QuantityInStock: 30
--ProductID: 3, ProductName: "Headphones", Price: 150.25, QuantityInStock: 50
--Can you write the SQL code to insert these values into the Products table?
insert into Products(ProductID,ProductName,Price,QuantityInStock)
values
(1, 'Laptop', 1200.50, 15),
(2, 'Smartphone', 800.00, 30),
(3, 'Headphones', 150.25, 50);
--3. Query to Retrieve All Products
--Write an SQL query to retrieve all the products from the Products table, including
--their ProductID, ProductName, Price, and QuantityInStock. What would the query look like?
select * from Products;
--4. Query with a Condition
--Write an SQL query to retrieve all products that have a QuantityInStock greater than 20.
--What would the query look like?
select * from Products
where QuantityInStock >20;
--5. Update a Product's Price
--Write an SQL query to update the price of the product with ProductID 2 (Smartphone) to
--750.00. What would the query look like?
update Products
set Price = 750.00
where ProductID = 2;
--6. Delete a Product
--Write an SQL query to delete the product with ProductID 3 (Headphones) from the
--Products table. What would the query look like?
delete from Products
where ProductID = 3;
--7. Count the Number of Products
--Write an SQL query to count the total number of products in the Products table.
--What would the query look like?
SELECT COUNT(*) FROM Products;
--8. Query to Find Products Below a Certain Price
--Write an SQL query to find all products that have a price less than 800.00.
--What would the query look like?
select * from Products
where Price < 800.00;
--9. Sorting Products by Price
--Write an SQL query to retrieve all products sorted by price in descending order.
--What would the query look like?
select * from Products
order by Price desc;
--10. Retrieve Product Information with a Specific Range of Quantities
--Write an SQL query to retrieve products with a QuantityInStock between 10 and 40
--(inclusive). What would the query look like?
select * from Products
where QuantityInStock between 10 and 40 ;
--11. Add a New Column
--Write an SQL statement to add a new column named Category (type: TEXT) to the Products
--table. What would the query look like?
alter table products
add category TEXT;