我有一张桌子
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
读数是一个累积值,我需要计算上个月和当月的差异。
你能帮我弄清楚如何生成一个视图,我可以在其中查看每个月的消费(上个月读数 - 本月读数)吗?
我尝试过 between 函数:
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;
但我得到的只是每个月的读数,而不是差异。
我怎样才能让它列出每月的消费?