gpt4 book ai didi

mysql - 重写 MySQL 查询并使其简短

转载 作者:行者123 更新时间:2023-11-29 06:30:37 25 4
gpt4 key购买 nike

有人可以帮我简化以下 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 的行

最佳答案

我认为您可以直接使用 payment_code = '123456789'条件。

SELECT * 
FROM customer_order_payments
WHERE payment_code = '123456789'
ORDER BY id DESC

关于mysql - 重写 MySQL 查询并使其简短,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56519949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com