I am trying to find a query for an income statement. This will require two tables: clicks and offers. Revenue is calculated by the number of conversions * commission per offer. Conversions are stored in the click table in a field called "conversionDate", and the fee for each offer is stored in the offer table.
The request must have a condition to ignore any clicks that are not converted (which means that convertDate is NULL) when adding revenue to the offer.
I have a need for customization, as it does not provide the correct value for revenue:
SELECT o.name offer, count (c.id) clicks if (not isnull (c.conversionDate), income = income + o.commission, income) revenue FROM clicks c, offers o, where c.offerID = o.ID GROUP BY o.ID;
I have 3 dummy click posts right now, 2 of which are conversions. If the commission is set to 1, the income should be equal to 2. The result that I get is equal to 1. Am I on the right track or should the calculation of income be some kind of subquery or what?
source
share