I have 2 tables:
I’m trying to make a request that brings the sum of hits and conversions per landing page,
But I want that if the landing page does not receive any hits and conversions ( and does not appear in the report table ), then I want the result to return 0 as a result.
What am I doing so far:
SELECT l.LandingPageId, SUM(Hits) AS Hits, SUM(PixelSum) AS Conversion
FROM Report c
RIGHT JOIN LandingPages l ON(c.LandingPageId = l.LandingPageId )
WHERE c.CampaignId = x
AND DayDate > 'y'
GROUP BY c.LandingPageId
The problem is that I only get rows with the landing page that exist in the report table and pass the date 'y',
(e.g.: I get only 2 rows of the landing page, but there are 4 landing pages
If I run this query, I get 4 results
SELECT l.LandingPageId FROM LandingPages l WHERE l.CampaignId = x
)
( 0 ),
, , , , ?
.
update:
, , , , , :
:
SELECT l.LandingPageId, IFNULL(SUM(Hits),0) AS Hits, IFNULL(SUM(PixelSum),0) AS Conversion
FROM LandingPages l
LEFT JOIN Report c ON( l.LandingPageId = c.LandingPageId)
WHERE (l.CampaignId = x OR l.CampaignId IS NULL)
AND (DayDate > 'y' OR DayDate IS NULL)
GROUP BY l.LandingPageId
!
!