I have this large query below which I joined five queries by the date:
--Combined Daily Actions Per Revenue Source--
SELECT Two.the_date,
sp_dau,
cs_dau,
tapjoy_ios_dau,
tapjoy_android_dau,
appcircle_ios_dau,
appcircle_android_dau,
freecause_dau,
portal_dau
FROM (SELECT Trunc(Cs.create_dtime) AS The_Date,
Count(DISTINCT CASE
WHEN Cs.cs_listing_id LIKE '99999999%' THEN
( Cs.player_id )
END) AS Sp_Dau,
Count(DISTINCT CASE
WHEN Cs.cs_listing_id NOT LIKE '99999999%' THEN
( Cs.player_id )
END) AS Cs_Dau
FROM player_chkin_cs Cs
WHERE Trunc(Cs.create_dtime) >= To_date('2012-Jan-01', 'yyyy-mon-dd')
GROUP BY Trunc(Cs.create_dtime)) One
INNER JOIN (SELECT Trunc(Tap.create_dtime) AS The_Date,
Count(DISTINCT CASE
WHEN ( Play.uuid LIKE 'i~%' )
OR ( Play.uuid LIKE 'ti~%' )
THEN
Tap.player_id
END) AS Tapjoy_Ios_Dau,
Count(DISTINCT CASE
WHEN ( Play.uuid LIKE 'a~%' )
OR ( Play.uuid LIKE 'ta~%' )
THEN
Tap.player_id
END) AS Tapjoy_Android_DAU
FROM player_tapjoy Tap
INNER JOIN player Play
ON Tap.player_id = Play.player_id
WHERE Trunc(Tap.create_dtime) >=
To_date('2012-Jan-01', 'yyyy-mon-dd')
GROUP BY Trunc(Tap.create_dtime)) Two
ON One.the_date = Two.the_date
INNER JOIN (SELECT Trunc(Aux.create_dtime) AS The_Date,
Count(DISTINCT CASE
WHEN ( Play.uuid LIKE 'i~%' )
OR ( Play.uuid LIKE 'ti~%' )
THEN
Aux.player_id
END) AS Appcircle_Ios_Dau,
Count(DISTINCT CASE
WHEN ( Play.uuid LIKE 'a~%' )
OR ( Play.uuid LIKE 'ta~%' )
THEN
Aux.player_id
END) AS AppCircle_Android_DAU
FROM player_aux_pt Aux
INNER JOIN player Play
ON Aux.player_id = Play.player_id
WHERE Aux.site = 'AppCircle'
AND Trunc(Aux.create_dtime) >=
To_date('2012-Jan-01', 'yyyy-mon-dd')
GROUP BY Trunc(Aux.create_dtime))Three
ON Two.the_date = Three.the_date
INNER JOIN (SELECT Trunc(Aux.create_dtime) AS The_Date,
Count(DISTINCT Aux.player_id) AS FreeCause_DAU
FROM player_aux_pt Aux
WHERE Aux.site = 'ext : freecause'
AND Trunc(Aux.create_dtime) >=
To_date('2012-Jan-01', 'yyyy-mon-dd')
GROUP BY Trunc(Aux.create_dtime))Four
ON Three.the_date = Four.the_date
INNER JOIN (SELECT Trunc(Aux.create_dtime) AS The_Date,
Count(DISTINCT Aux.player_id) AS Portal_DAU
FROM player_aux_pt Aux
WHERE ( Aux.site = 'Portal : Promotion'
OR Aux.site = 'Portal : RadiumOne'
OR Aux.site = 'Portal : Paymentwall'
OR Aux.site = 'Portal : TrialPay' )
AND Trunc(Aux.create_dtime) >=
To_date('2012-Jan-01', 'yyyy-mon-dd')
GROUP BY Trunc(Aux.create_dtime)) Five
ON Four.the_date = Five.the_date
Most of the subqueries range from 2012-Jan-01 to present date, except for one that only have data from 09-Jul-12 to present.
So, when I run this query, the first date in the result is 09-Jul-12 and not 01-Jan-12.
How can I get the results to start at Jan 01, where all but one query has relevant data for?
Your problem is that the dates are dropping out because they do not match. The answer to your question is
LEFT OUTER JOINinstead ofINNER JOIN. This keeps all rows in the first table (left side of the join), along with any matching information in the next table. If there is no match, all the values become NULL.Assuming that the first table has all the dates that you want, then change the join in all the subsequent queries.
If you want 0’s instaed of NULL, then use
coalesce()in theselectclause to convert them.