मैं क्वेरी इस तरह लिखूंगा:
SELECT o.name AS offer, COUNT(c.id) AS clicks,
SUM( IF(c.conversionDate IS NOT NULL, o.commission, NULL) ) AS revenue
FROM offers o JOIN clicks c ON (c.offerID=o.ID)
GROUP BY o.ID;
यहां एक और समाधान है, लेकिन ऐसे ऑफ़र हैं जिनमें कोई नहीं है रूपांतरित क्लिक क्वेरी परिणाम में नहीं दिखाए जाते:
SELECT o.name AS offer, COUNT(c.id) AS clicks,
SUM(o.commission) AS revenue
FROM offers o JOIN clicks c
ON (c.offerID=o.ID AND c.conversionDate IS NOT NULL)
GROUP BY o.ID;