What does this SQL query do?
💡 Model Answer
This SQL statement aggregates purchase amounts by store and customer. It selects the store_id and customer_id columns, and computes the sum of purchase_amt for each combination of store and customer, naming the result total_amount. The GROUP BY clause groups rows that have the same store_id and customer_id, so the SUM() function is applied to each group. The result is a table where each row represents a unique store–customer pair and the total amount they spent. This is useful for reporting or billing purposes. The query runs in linear time relative to the number of rows in the purchase table, assuming the database can efficiently group and aggregate. Indexes on store_id and customer_id can improve performance. If you need to filter the results, you can add a WHERE clause before the GROUP BY. In summary, the query provides a per‑store, per‑customer total purchase amount.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500