By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE YourTable (
"Employee" VARCHAR(5),
"Date" VARCHAR(10),
"hours" INTEGER
);
INSERT INTO YourTable
("Employee", "Date", "hours")
VALUES
('Rohit', '06-03-2022', '9'),
('Rohit', '07-03-2022', '8'),
('Rohit', '08-03-2022', '9'),
('Rohit', '09-03-2022', '9'),
('Rohit', '10-03-2022', '10'),
('Rohit', '11-03-2022', '8'),
('Rohit', '12-03-2022', '8'),
('Rohit', '06-03-2022', '7'),
('Raj', '07-03-2022', '8'),
('Raj', '08-03-2022', '4'),
('Raj', '09-03-2022', '3'),
('Raj', '10-03-2022', '5'),
('Raj', '11-03-2022', '8'),
('Raj', '12-03-2022', '8');
14 rows affected
SELECT
Employee = CASE WHEN GROUPING(t.Date) = 0 THEN t.Employee ELSE 'Total' END,
t.Date,
hours = SUM(t.hours)
FROM YourTable t
GROUP BY GROUPING SETS (
(Employee, Date),
(Employee)
);
Employee | Date | hours |
---|---|---|
Raj | 07-03-2022 | 8 |
Raj | 08-03-2022 | 4 |
Raj | 09-03-2022 | 3 |
Raj | 10-03-2022 | 5 |
Raj | 11-03-2022 | 8 |
Raj | 12-03-2022 | 8 |
Total | null | 36 |
Rohit | 06-03-2022 | 16 |
Rohit | 07-03-2022 | 8 |
Rohit | 08-03-2022 | 9 |
Rohit | 09-03-2022 | 9 |
Rohit | 10-03-2022 | 10 |
Rohit | 11-03-2022 | 8 |
Rohit | 12-03-2022 | 8 |
Total | null | 68 |