Untitled
unknown
plain_text
2 years ago
515 B
8
Indexable
-- Add a new column named 'Output'
ALTER TABLE your_table
ADD Output DATE;
-- Update the 'Output' column with the calculated values
UPDATE your_table
SET Output =
CASE
WHEN EXISTS (
SELECT 1
FROM your_table t2
WHERE t2.age = your_table.age
AND t2.city = your_table.city
AND t2.country = your_table.country
AND t2.fromdate > your_table.fromdate
) THEN DATEADD(day, -1, todate)
ELSE todate
END;
Editor is loading...