Orders Saved Twice
EasyDescription
The checkout sometimes saves an order twice. First run these statements, which save order 20 once more and order 41 twice more:
CodeINSERT INTO orders (customer_id, order_date, status, total_amount, shipping_city) SELECT customer_id, order_date, status, total_amount, shipping_city FROM orders WHERE order_id IN (20, 41); INSERT INTO orders (customer_id, order_date, status, total_amount, shipping_city) SELECT customer_id, order_date, status, total_amount, shipping_city FROM orders WHERE order_id = 41;
Two orders are copies when they have the same customer_id, order_date, total_amount
and shipping_city. For every group of copies, show:
customer_id,order_dateandtotal_amountcopies: how many orders are in the groupfirst_order_id: the lowestorder_idin the group
End your query with ORDER BY customer_id, order_date.
Tables
| orders |
|---|
| order_id (PK) |
| customer_id (FK) |
| order_date |
| status |
| total_amount |
| shipping_city |