The order table is made up of quantity, price, username and orderdate which is in datetime format.
An order is submitted from a cart page, if multiple items are submitted such as 8 monitors and 2 pcs. It will input those as two separate records.
The goal: To multiply the quantity by the price for each record a user has, then to add those records up for the last 30 days.
Tried the below code to get the orders from the last 30 days which isnt working.
edit: working code for getting orders from last 30 days
SELECT * FROM `orders`
where orderdate between adddate(now(),-30) and now()
Honestly not sure where to start with the above sql statement, not sure where exactly the groupbys, count and sum() functions go since I am only starting with sql.
3
Answers
You can use below query
If you need to count row and sum the sales price
Alternatively, if you wanted these queries by username,
Be more explicit:
Or, because you probably do not care about the time component:
In order to get the “total order value” for the last 30 days, you need to calculate
SUM()
onprice*quantity
: