-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass 15.sql
More file actions
71 lines (56 loc) · 2.64 KB
/
class 15.sql
File metadata and controls
71 lines (56 loc) · 2.64 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
create database tushar;
use tushar;
CREATE TABLE EmployeeSales (
EmployeeID INT,
EmployeeName VARCHAR(100),
Department VARCHAR(50),
SaleDate DATE,
SaleAmount DECIMAL(10, 2)
);
INSERT INTO EmployeeSales (EmployeeID, EmployeeName, Department, SaleDate, SaleAmount) VALUES
(1, 'Alice', 'Sales', '2025-06-01', 1200.00),
(1, 'Alice', 'Sales', '2025-06-03', 1800.00),
(1, 'Alice', 'Sales', '2025-06-07', 1500.00),
(2, 'Bob', 'Sales', '2025-06-01', 2000.00),
(2, 'Bob', 'Sales', '2025-06-05', 2200.00),
(2, 'Bob', 'Sales', '2025-06-08', 2100.00),
(3, 'Carol', 'Marketing', '2025-06-02', 3000.00),
(3, 'Carol', 'Marketing', '2025-06-06', 2800.00),
(3, 'Carol', 'Marketing', '2025-06-10', 2700.00),
(4, 'Dave', 'Marketing', '2025-06-01', 1000.00),
(4, 'Dave', 'Marketing', '2025-06-03', 1100.00),
(4, 'Dave', 'Marketing', '2025-06-09', 1300.00),
(5, 'Eve', 'HR', '2025-06-04', 900.00),
(5, 'Eve', 'HR', '2025-06-07', 950.00),
(5, 'Eve', 'HR', '2025-06-10', 1000.00),
(6, 'Frank', 'Sales', '2025-06-02', 1700.00),
(6, 'Frank', 'Sales', '2025-06-05', 1900.00),
(6, 'Frank', 'Sales', '2025-06-09', 1600.00),
(7, 'Grace', 'Finance', '2025-06-01', 2500.00),
(7, 'Grace', 'Finance', '2025-06-06', 2400.00),
(7, 'Grace', 'Finance', '2025-06-10', 2600.00),
(8, 'Hank', 'Finance', '2025-06-03', 2300.00),
(8, 'Hank', 'Finance', '2025-06-04', 2200.00),
(8, 'Hank', 'Finance', '2025-06-08', 2100.00),
(9, 'Ivy', 'HR', '2025-06-02', 800.00),
(9, 'Ivy', 'HR', '2025-06-06', 850.00),
(9, 'Ivy', 'HR', '2025-06-09', 950.00),
(10, 'Jake', 'IT', '2025-06-05', 3000.00),
(10, 'Jake', 'IT', '2025-06-07', 3200.00),
(10, 'Jake', 'IT', '2025-06-10', 3100.00);
select * from employeeSales;
select sum(SaleAmount) as totalsale from EmployeeSales;
select EmployeeName ,sum(SaleAmount) from EmployeeSales group by EmployeeName ;
-- windows function
select *,
sum(saleamount) over(),
avg(saleamount) over() from employeeSales ;
select employeename, saleamount , max(saleamount) over() from employeesales ;
select employeename, saleamount , min(saleamount) over() from employeesales ;
select employeename, saleamount , min(saleamount) over(partition by employeename) from employeesales ;
select employeename, saleamount , max(saleamount) over(partition by department) from employeesales ;
select *, min(saleamount) over(partition by employeename) from employeesales ;
select *, max(saleamount) over () , min(saleamount) over(partition by employeename) from employeesales ;
-- over (order by ) -- runing sum (cummulative sum )
select *, sum(saleamount) over(order by saleamount desc) from employeesales;
select *, sum(saleamount) over(partition by department order by saleamount ) from employeesales ;