sql >> Database teknologi >  >> RDS >> Oracle

Oracle SQL:Hvordan viser man tomme uger/uger uden data?

Brug en partitioneret ydre joinforbindelse :

select data.id, weeks.weekend_day, nvl(value, 0) value
from
(
    select date '2012-01-01' weekend_day from dual union all
    select date '2012-01-08' weekend_day from dual union all
    select date '2012-01-15' weekend_day from dual
) weeks
left join
(
    select 'A00' id, date '2012-01-01' weekend_day, 1 value from dual union all
    select 'A00' id, date '2012-01-08' weekend_day, 7 value from dual union all
    select 'B00' id, date '2012-01-08' weekend_day, 4 value from dual union all
    select 'B00' id, date '2012-01-15' weekend_day, 3 value from dual
) data
    partition by (data.id)
    on weeks.weekend_day = data.weekend_day


  1. De første to lønninger i hver afdeling

  2. Ruby on rails forbindelsesproblem

  3. Forklar uforklarlig dødvande

  4. T-SQL understreng - adskiller for- og efternavn