Soft delete pattern
SQL
Hard
3 views
Problem Description
Instead of deleting customers, keep the row and mark it inactive. Add is_active (default 1) and set is_active=0 for customers who have no orders in the last 2 years.
Input Format
SQL DDL + DML
Constraints
Assume PostgreSQL-style interval
Official Solution
ALTER TABLE Customers ADD COLUMN is_active INT DEFAULT 1; UPDATE Customers SET is_active = 0 WHERE customer_id NOT IN (SELECT DISTINCT customer_id FROM Orders WHERE order_date >= (CURRENT_DATE - INTERVAL '730 days'));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!