Skip to content

Commit 04aad70

Browse files
Add files via upload
1 parent 81fbcbf commit 04aad70

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

‎SQL Practice 06-05-2025.sql‎

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
-- left join
2+
3+
create database mpk;
4+
5+
use mpk;
6+
7+
CREATE TABLE Customers (
8+
CustomerID INT PRIMARY KEY,
9+
FirstName VARCHAR(50),
10+
LastName VARCHAR(50),
11+
Email VARCHAR(100)
12+
);
13+
14+
CREATE TABLE Orders (
15+
OrderID INT PRIMARY KEY,
16+
CustomerID INT,
17+
OrderDate DATE,
18+
TotalAmount DECIMAL(10, 2)
19+
);
20+
21+
INSERT INTO Customers (CustomerID, FirstName, LastName, Email)
22+
VALUES
23+
(1,'Anvi','Mathur','anvimathur@booksstore.com'),
24+
(2,'Tanvi','Thakur','tanvithakur@booksstore.com'),
25+
(3,'Raj','Patel','rajpatel@booksstore.com'),
26+
(4,'Arnav','Gupta','arnavgupta@booksstore.com'),
27+
(5,'Jui','Jadhav','juijadhav@booksstore.com'),
28+
(8,'Ravi','Sharma','ravisharma@booksstore.com'),
29+
(10,'Geeta','Jog','geetajog@booksstore.com');
30+
31+
INSERT INTO Orders (OrderID, CustomerID, OrderDate, TotalAmount)
32+
VALUES
33+
(101,1,'2023-07-15',275.00),
34+
(102,2,'2023-02-20',200.50),
35+
(103,3,'2022-05-26',353.75),
36+
(111,11,'2024-05-26',150.00),
37+
(109,4,'2023-05-15',360.00),
38+
(112,9,'2023-02-20',225.00);
39+
40+
41+
select * from customers;
42+
select * from orders;
43+
44+
45+
select customers.firstname , customers.email , orders.orderdate , orders.totalamount
46+
from customers left join orders
47+
on customers.customerid = orders.customerid;
48+
49+
50+
-- right join
51+
52+
select customers.firstname , customers.email , orders.orderdate , orders.totalamount
53+
from customers right join orders
54+
on customers.customerid = orders.customerid;
55+
56+
-- inner join
57+
select customers.firstname , customers.email , orders.orderdate , orders.totalamount
58+
from customers inner join orders
59+
on customers.customerid = orders.customerid;
60+
61+
-- full join
62+
select customers.firstname , customers.email , orders.orderdate , orders.totalamount
63+
from customers left join orders
64+
on customers.customerid = orders.customerid
65+
union
66+
select customers.firstname , customers.email , orders.orderdate , orders.totalamount
67+
from customers right join orders
68+
on customers.customerid = orders.customerid;
69+
70+
-- Date
71+
72+
SELECT NOW(); -- e.g., 2025-05-05 14:30:00
73+
SELECT CURDATE(); -- e.g., 2025-05-05
74+
SELECT CURTIME(); -- e.g., 14:30:00
75+
SELECT CURRENT_TIMESTAMP(); -- e.g., 2025-05-05 14:30:00
76+
77+
select orderdate , year(orderdate) from orders;
78+
select orderdate , month(orderdate) from orders;
79+
select orderdate , day(orderdate) from orders;
80+
81+
-- DATE_ADD
82+
select orderdate , DATE_ADD(orderdate , interval 7 Day) as new_date from orders;
83+
select orderdate , DATE_ADD(orderdate , interval 7 year) as new_date from orders;
84+
select orderdate , DATE_ADD(orderdate , interval 7 month) as new_date from orders;
85+
86+
-- DATE_SUB
87+
88+
select orderdate , DATE_SUB(orderdate , interval 4 month) as new_date from orders;
89+
select orderdate , DATE_SUB(orderdate , interval 4 Day) as new_date from orders;
90+
select orderdate , DATE_SUB(orderdate , interval 4 year) as new_date from orders;
91+
92+
-- CONCAT
93+
94+
select * from customers;
95+
96+
97+
-- CONCAT
98+
99+
select * , concat(firstname," ",lastname) as full_name from customers;
100+
101+
-- LENGTH
102+
select * , LENGTH(concat(firstname," ",lastname)) as full_name from customers;
103+
104+
select * , upper(concat(firstname," ",lastname)) as full_name from customers;
105+
106+
107+
-- SUBSTRING
108+
109+
select firstname , SUBSTRING(firstname,1,2) as Nckname from customers;
110+
111+
-- REPLACE
112+
select email , REPLACE(email,'booksstore.com','bs.in') as new_email
113+
from customers;
114+

0 commit comments

Comments
 (0)