gpt4 book ai didi

Mysql查询获取对象总数

转载 作者:行者123 更新时间:2023-11-30 00:50:33 24 4
gpt4 key购买 nike

我有一个疑问:

SELECT t1.id, 
t3.title,
Count(t2.city_id) AS objectsCount
FROM geo_data AS t1
INNER JOIN object AS t2
ON t1.uid = t2.city_id
AND t2.is_blocked = 0
JOIN geo_data_translation AS t3
ON t1.id = t3.id
AND t3.language_id = 'de'
WHERE t1.is_city = 1
GROUP BY name;

结果是:

+-----+------------------------------+--------------+
| id | title | objectsCount |
+-----+------------------------------+--------------+
| 404 | Achim | 1 |
| 85 | Ahrensburg | 3 |
| 305 | Ahrensfelde | 2 |
| 471 | Aichach | 1 |
| 377 | Alfeld (Leine) | 1 |
| 373 | Algermissen | 2 |
| 465 | Allershausen | 1 |
| 525 | Alsheim | 1 |
| 152 | Altenmoor | 1 |
| 482 | Anzing | 1 |
| 518 | Armsheim | 3 |
| 562 | Arnsdorf | 1 |
| 109 | Artlenburg | 1 |
| 476 | Aschheim | 1 |
| 224 | Asendorf | 1 |
| 436 | Augusta | 1 |
| 447 | Aystetten | 1 |
| 360 | Banteln | 1 |

我们看到的是一个城市列表及其对象数量。Achim 市有 1 个对象,Ahrensburg 有 3 个对象,依此类推

我想做的是获取所有列出的城市的总对象数。谢谢

最佳答案

select t1.title,sum(t1.objectscount)as 'total_count' from table1 t1 
group by t1.title

关于Mysql查询获取对象总数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21019274/

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