H5 Vay liền: Vay tiền siêu tốc nhanh online 24/7
Certainly! Assuming you have an "orders" table, you can use the following SQL query to add a "status" column with a default value of 'PENDING' and update it to 'COMPLETE' if the "completed_at" column is set:
```sql
-- Add the "status" column with a default value of 'PENDING'
ALTER TABLE orders
ADD COLUMN status VARCHAR(255) DEFAULT 'PENDING';
-- Update the "status" to 'COMPLETE' where "completed_at" is set
UPDATE orders
SET status = 'COMPLETE'
WHERE completed_at IS NOT NULL;
```
This query first adds the "status" column to the "orders" table with a default value of 'PENDING'. Then, it updates the "status" to 'COMPLETE' for those rows where the "completed_at" column is not null.
4.9/5 (88 votes)