Skip to content

Commit d950dc9

Browse files
authored
Update 8_cwpc_9.sql
1 parent 7326806 commit d950dc9

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

‎Example-File/8_cwpc_9.sql‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,52 @@ select country from customers group by country;
226226
select country,count(country) as total_customer from customers group by country;
227227

228228

229+
-- Date : 6 - 12 - 2025
230+
-- distinct keyword
231+
232+
use classicmodels;
233+
234+
select distinct country from customers;
235+
236+
-- Constraints (key)
237+
create database ecom;
238+
use ecom;
239+
240+
CREATE TABLE Customers (
241+
CustomerID INT PRIMARY KEY,
242+
Name VARCHAR(50),
243+
City VARCHAR(50),
244+
email varchar(100) unique key
245+
);
246+
247+
CREATE TABLE Orders (
248+
OrderID INT PRIMARY KEY,
249+
CustomerID INT,
250+
OrderDate DATE,
251+
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
252+
);
253+
254+
255+
select * from customers;
256+
select * from orders;
257+
insert into orders value(101,1,'2025-01-12');
258+
insert into customers value(1,"Joy",'Mumbai','joy@gmail.com');
259+
260+
-- truncate table
261+
truncate table customers;
262+
263+
-- having
264+
SELECT SalespersonName, SUM(SaleAmount) AS TotalSales
265+
FROM Sales
266+
GROUP BY SalespersonName
267+
HAVING SUM(SaleAmount) > 200;
268+
269+
use classicmodels;
270+
select * from customers;
271+
272+
select country , sum(creditlimit) as total_credit
273+
from customers group by country having sum(creditlimit) > 500000;
274+
229275

230276

231277

0 commit comments

Comments
 (0)