I would like to get the last row from every order and the quantity of the last row but one:
SELECT o.order_id, o.order_user, o.Q, Q_before=(SELECT TOP 1 Q FROM dbo.orders WHERE order_id=o.order_id AND order_date<o.order_date
ORDER BY order_date DESC) FROM dbo.Orders AS o
How can this be done with new functions in SQL 2012?