最後掛單我有Customers
創造了一些Order
小號存儲在訂單postgres
db.Some可能有'pending'
status.I希望用戶能夠在他的最後掛單工作。檢索客戶
順序表
id | order_num | order_date |customer_id | status
-----+-----------+------------+------------+---------
80 | 1234 | 02-01-2000 | 20 | pending
----------------------------------------------------
81 | 2345 | 02-01-2000 |20 | confirmed
-----------------------------------------------------
82 | 3456 | 02-01-2000 |20 | pending
--------------------------------------------------
83 | 3498 | 02-001-2000| 20 | confirmed
----------------------------------------------------
這有什麼錯用
select * from orders where customer_id =20 and status='pending' order by id DESC limit 1
多個記錄的order_date的可能same.The訂單號可能並不總是按升序排列。在這方面是否通過id命令安全?
如何根據'order_num'排序? –