gpt4 book ai didi

Mysql 连接有限制

转载 作者:行者123 更新时间:2023-11-29 14:05:46 24 4
gpt4 key购买 nike

我的查询是这样的......

SELECT tb1.name, COUNT(tb2.payment_date) as first_payment FROM table1 LEFT JOIN table2 tb2 ON tb2.id_user = tb1.id

+-----------+-------------+
| Name | Count |
+-----------+-------------+
| John | 543534543 |

但我希望我的查询返回连接限制,例如:

LEFT JOIN tb2 ON tb2.id_user = tb1.id { LIMIT JOIN }

仅返回一种关系......

+-----------+-------------+
| Name | Count |
+-----------+-------------+
| John | 3 |

最佳答案

select tb1.name, count(*) as first_payment
from table1 t1
LEFT JOIN (SELECT id_user, min(payment_date)
FROM table2
GROUP BY id_user) as t2
ON t1.id = t2.id_user
GROUP BY tb1.name

关于Mysql 连接有限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14379367/

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