Vay tien tra gop theo ngay
You can achieve this in SQL by adding a new column to your existing orders table and using a CASE statement to determine the value of the status column based on the value of the completed_at column. Here's the SQL query to achieve that:
```sql
ALTER TABLE orders
ADD COLUMN status VARCHAR(20) DEFAULT 'PENDING';
UPDATE orders
SET status = CASE
WHEN completed_at IS NOT NULL THEN 'COMPLETE'
ELSE 'PENDING'
END;
```
This SQL code first adds a new column called "status" to the "orders" table with a default value of 'PENDING'. Then, it updates the "status" column for each row in the table using a CASE statement. If the "completed_at" column is not NULL, it sets the "status" column to 'COMPLETE'; otherwise, it sets it to 'PENDING'.
4.9/5 (80 votes)