gpt4 book ai didi

postgresql - Postgres : how to excecute the query for Sum as it is giving error?

转载 作者:行者123 更新时间:2023-12-05 01:13:09 24 4
gpt4 key购买 nike

我正在使用 sum 函数求总数但出现错误。这是查询:

select sum(col1) 
from table_name
where col2="abc"
Error: function sum(text) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts

最佳答案

假设 text 列包含 text 数字,而不是实际整数,那么它将解释您看到的错误。您可以通过首先将 text 转换为整数,然后求和来解决这个问题:

SELECT SUM(text::int)
FROM yourTable;

关于postgresql - Postgres : how to excecute the query for Sum as it is giving error?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60862461/

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