I have a table called orders this table contains all the information we need.
I’ll just list the columns we need for the query:
purchase_price(always contains the total amount paid for the order)pay_method((int) when1it means the fullpurchase_pricewas paid for in cash, when3it meanspurchase_pricewas only paid partially in cash, other values mean other paying means so ignore them.)cash_paid(when thepay_methodis3this column contains the amount of cash paid for the order, note that this is not the total price, it’s just the part ofpurchase_pricethat was paid for in cash. Whenpay_methodis NOT3this field’s value is0date((datetime)simply the date+time on which the order was placed)
The idea is pretty simple. we need to get the total amount of cash payed grouped by day.
But we found this a pretty hard task.
PS: I’m playing around with this problem in PHP using MySQL, so it’s alright to use multiple queries and/or use some PHP script.
Use MySQL IF-function:
If the pay_method is 1, take the purchase_price field. Else take the cash_paid field.