Untitled

Anonymous
plain_text
10/11/2023 1:19 PM
688 B
18
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...