gpt4 book ai didi

mysql - 计算mysql中的各个行

转载 作者:行者123 更新时间:2023-11-29 07:35:36 25 4
gpt4 key购买 nike

我有以下贷款模式:

mysql> select * from borrower;
+----------+---------+
| name | loan_id |
+----------+---------+
| Adams | L16 |
| Curry | L93 |
| Hayes | L15 |
| Jackson | L14 |
| Jones | L17 |
| Smith | L11 |
| Smith | L23 |
| Williams | L17 |
+----------+---------+
8 rows in set (0.00 sec)

我需要计算每个人获得的贷款总数。我认为自连接是解决这个问题的方法,我尝试了以下查询:

select T1.name, count(T2.name) from borrower T1, borrower T2 where T1.name = T2.name;

但是我得到了如下奇怪的结果:

mysql> select T1.name, count(T2.name) from borrower T1, borrower T2 where T1.name = T2.name;
+-------+----------------+
| name | count(T2.name) |
+-------+----------------+
| Adams | 10 |
+-------+----------------+
1 row in set (0.00 sec)

最佳答案

你可以试试这个:

select name, count(name) from borrower
group by name

关于mysql - 计算mysql中的各个行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30917659/

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