I am running the following query using DBISAM
SELECT((SUM(sales.sale_amount)
+SUM(sales.vat_amount))
-SUM(payments.fee_amount))
AS Balance,account_details.id FROM account_details
JOIN sales ON account_details.id = sales.account_id
JOIN payments ON account_details.id = payments.account_id GROUP BY account_details.id
However, there are 3 different types of sale - sales.sale_type equating to 0, 1 or 2. If it is 0 a positive sale_amount and vat_amount should be added, ELSE negative values should be used.
I've tried various
IF(sales.sale_type=0)
BEGIN
...
END
ELSE
BEGIN
...
END
To no avail, encountering only errors with the script not even runnning. I don't know if these errors are confined to DBISAM or it is my SQL in general.
Any help appreciated.
Thanks