有人可以帮助我简化以下MySQL查询吗?该查询工作正常,但我只想简化查询并使之易于阅读。
SELECT *
FROM customer_order_payments
WHERE customer_order_id = (SELECT customer_order_id FROM customer_order_payments WHERE payment_code = 'O1529P03N001')
ORDER BY id DESC
表结构如下
+-------------------+--------------+
| customer_order_id | payment_code |
+-------------------+--------------+
| 1528 | O1528P09N002 |
| 1528 | O1528P07N001 |
| 1528 | O1528P09N003 |
| 1529 | O1529P03N001 |
| 1529 | O1529P03N004 |
| 1529 | O1529P03N003 |
| 1529 | O1529P03N002 |
| 1598 | O1598P03N001 |
| 1608 | O1608P03N001 |
| 1610 | O1610P20N001 |
| 1620 | O1620P03N002 |
| 1620 | O1620P03N001 |
| 1634 | O1634P03N003 |
| 1634 | O1634P03N004 |
| 1634 | O1634P03N001 |
| 1634 | O1634P03N002 |
| 1645 | O1645P03N001 |
| 1655 | O1655P02N001 |
| 1663 | O1663P20N001 |
| 1694 | O1694P03N001 |
+-------------------+--------------+
查询将返回customer_order_id全部为1529的行
答案 0 :(得分:2)
我认为您可以直接使用payment_code = '123456789'
条件。
SELECT *
FROM customer_order_payments
WHERE payment_code = '123456789'
ORDER BY id DESC
答案 1 :(得分:0)
选择* FROM customer_order_payments WHERE payment_code ='123456789'按ID DESC排序