cmglaze / test

0 stars 0 forks source link

Write a SQL query for getting sales from orders table for the last 3 days date wise #152

Open cmglaze opened 1 year ago

cmglaze commented 1 year ago

EXAMPLE RESPONSE: Assuming that the date column in the orders table is named as order_date, the SQL query for getting sales from orders table for the last 3 days date wise would be:

SELECT order_date, SUM(sales) AS total_sales FROM orders WHERE order_date >= DATE(NOW()) - INTERVAL 3 DAY GROUP BY order_date ORDER BY order_date ASC

This query will retrieve the sales for the last 3 days date wise and group them accordingly. The NOW() function retrieves the current date and time, and the DATE() function formats the date portion of it. The INTERVAL 3 DAY clause specifies that we want sales from the last 3 days, and the WHERE clause filters the results accordingly. Finally, the GROUP BY clause groups the sales by date, and the ORDER BY clause sorts the results in ascending order of date.