Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have a table of time sampled data as follows:

Meter Number|Sample Date|Meter Reading
      1      30/04/2014      123
      1      22/05/2014      456
      1      29/06/2014      789
      2      30/04/2014      246
      2      29/05/2014      802
      2      23/06/2014      1468

My question is, how do I structure a query to return the previous months value and the current months value in one row based on a search date. For example:

Return usage for May (05/2014)
Meter number|Last Sample Date|Last Sample Value|Current Sample Date|Current Sample Value
      1         30/04/2014            123           22/05/2014               456
      2         30/04/2014            246           29/05/2014               802
share|improve this question
Could you please let us know which SQL DBMS you are using and which version? –  Simon Byles May 22 at 7:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.