I have data in two tables, same data but different approach, to get the result I'm going for. But then, I'm stuck and I was hoping you could point me in the right direction...
TABLE#1
CREATE TABLE table1
(Date, Col_A, Col_B, Col_C, Unknown)
;
INSERT INTO table1
(Date, Col_A, Col_B, Col_C, Unknown)
VALUES
('1-3-2023','2','1','5','1'),
('2-3-2023','6','0','1','2'),
('3-3-2023','0','0','1','1'),
('4-3-2023','5','0','2','3')
;
TABLE#2...
CREATE TABLE table2
(Date, Col_Name, Amount)
;
INSERT INTO table2
(Date, Col_Name, Amount)
VALUES
('1-3-2023','Col_A','2'),
('1-3-2023','Col_B','1'),
('1-3-2023','Col_C','5'),
('1-3-2023','Unknown','1'),
('2-3-2023','Col_A','6'),
('2-3-2023','Col_B','0'),
('2-3-2023','Col_C','1'),
('2-3-2023','Unknown','2'),
('3-3-2023','Col_A','0'),
('3-3-2023','Col_B','0'),
('3-3-2023','Col_C','1'),
('3-3-2023','Unknown','1'),
('4-3-2023','Col_A','5'),
('4-3-2023','Col_B','0'),
('4-3-2023','Col_C','2'),
('4-3-2023','Unknown','3')
;
I've been trying to add the Unknown value to the highest value in Col_A, Col_B or Col_C (per day) in Table#1 or to the highest value where Col_Name is Col_A, Col_B or Col_C (per day) in Table#2.
(select MAX(test) FROM (VALUES (Col_A),(Col_B),(Col_C)) AS value(test)) as Test gave me the highest value per day in Table#1, but I see no way to add this to the column with the highest value in a row.
The desired result is..:
Date Col_A Col_B Col_C
1-3-2023 2 1 6
2-3-2023 8 0 1
3-3-2023 0 0 2
4-3-2023 8 0 2
Many thanks in advance...