Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
515 B
2
Indexable
Never
-- 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;