gpt4 book ai didi

mysql - 带有连接查询的两个表中 mysql 中每个单独的 id 的计数

转载 作者:太空宇宙 更新时间:2023-11-03 12:30:31 25 4
gpt4 key购买 nike

<分区>

我有两张表,

表_1

id  team_id  fav_id
1 10 1
2 10 6
3 11 5
4 12 5
5 12 1
6 25 6

表_2

league_id   team_id   name
100 10 a
100 11 b
100 12 c
100 13 d
101 25 e

我需要 table_2 中所有 team_idleague_id = 100join 的结果在单个查询中 table_1 中每个 team_idfav_id 的计数

期待这样的结果,

league_id   team_id  name  count of(fav_id)
-------------------------------------------------
100 10 a 2
100 11 b 1
100 12 c 2
100 13 d 0

有什么想法吗?

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