我有一個表累積差異
Meter_Reading
MeterID | Reading | DateRead |
1 10 1-Jan-2012
1 20 2-Feb-2012
1 30 1-Mar-2012
1 60 2-Apr-2012
1 80 1-May-2012
閱讀是一個累積值,其中我需要計算從上月和本月的差別。
你能幫我弄清楚如何生成一個視圖,我可以看到每個月的消耗量(上個月的讀數 - 當前月份讀數)?
我曾試圖功能之間:
select address, reading as Consumption, dateread
from ServiceAddress, reading, meter
where address like '53 Drip Drive%'
and dateread
between (to_date('01-JAN-2012','DD-MON-YYYY')) and (to_date('30-SEP-2012', 'DD-MON-YYYY'))
and serviceaddress.serviceaddid = meter.serviceaddid and meter.meterid = reading.meterid;
但我得到的是每月不差的讀數。
我怎樣才能讓它列出每月消費?
如果一個月不見了會發生什麼? –
我想它會跳過它? –