sql >> Databasteknik >  >> RDS >> Oracle

Oracle SQL:Hur visar man tomma veckor/veckor utan data?

Använd en partitionerad yttre koppling :

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. Kan jag upptäcka och hantera MySQL-varningar med PHP?

  2. Vilken SqlDbType mappar till varBinary(max)?

  3. Skapa en tabell i MySQL

  4. SQLSTATE[HY093] :pdo-sats under infogning i mysql db