我想在表中某项的最后一条记录之前获得上一条记录
SELECT MAX(BillID), ConsumerID_FK,
SELECT CurrentReading FROM tblReading ORDER BY ReadingID DESC LIMIT 1,1) AS
'PreviousReading',
CurrentReading
FROM tblBilling b INNER JOIN tblReading r ON r.ReadingID = b.ReadingID_FK
INNER JOIN tblconsumer c ON c.ConsumerID = r.ConsumerID_FK
GROUP BY r.ReadingID
仅返回ConsumerID_FK=28
的上一条记录。以前的11读数是21。我想为所有消费者做到这一点。
我希望它返回每个消费者的先前读数。
Max(billID) | ConsumerID_FK | Previous Reading | CurrentReading
------------------------------------------------------------------
1 | 11 | 21 | 32
2 | 28 | 12 | 16