Certainly! You can use the following SQL query to add a "status" column to an existing "orders" table and set its default value to 'PENDING'. Additionally, if the "completed_at" column is set (not null), it will update the "status" column to 'COMPLETE':
```sql
ALTER TABLE orders
ADD COLUMN status VARCHAR(20) DEFAULT 'PENDING';
UPDATE orders
SET status = 'COMPLETE'
WHERE completed_at IS NOT NULL;
```
Replace 'orders' with the name of your table if it's different, and adjust the column types according to your specific requirements.
4.8/5 (105 votes)