gpt4 book ai didi

sql - 错误 : aggregate function calls cannot be nested - POSTGRESQL

转载 作者:行者123 更新时间:2023-11-29 12:39:25 49 4
gpt4 key购买 nike

我正在尝试创建一个包含 30 天内记录历史记录的选择,其中值列获得计数,我只希望它会添加每天返回的值。

查询

SELECT
date_update AS Time,
SUM(COUNT(values)) as "Value"
FROM
tb_get_metrics
WHERE
data_update >= CURRENT_DATE - 30
GROUP BY Time
ORDER BY Time

示例输出:

       Time                      Value
2019-10-14 09:46:54.789772 30
2019-10-15 09:46:54.789772 50
2019-10-16 09:46:54.789772 70

SELECT * FROM tb_get_metrics

  date_update(TimeStamp)        value(String)
2019-10-14 09:46:54.789772 apple
2019-10-14 09:46:55.789772 apple
2019-10-14 09:46:56.789772 apple
2019-10-14 09:46:57.789772 apple
2019-10-14 09:46:58.789772 apple
2019-10-14 09:46:59.789772 apple
2019-10-14 09:47:00.789772 apple
2019-10-14 09:46:01.789772 apple
2019-10-14 09:46:02.789772 apple
2019-10-14 09:46:03.789772 apple
2019-10-14 09:46:04.789772 apple
2019-10-14 09:46:05.789772 apple
2019-10-15 09:46:03.789772 potato
2019-10-15 09:46:04.789772 potato
2019-10-15 09:46:05.789772 potato
...

最佳答案

您需要将时间四舍五入到日期:

SELECT
date_update::date AS "Date",
COUNT(values) as "Value"
FROM
tb_get_metrics
WHERE
data_update >= CURRENT_DATE - 30
GROUP BY Time
ORDER BY Time

关于sql - 错误 : aggregate function calls cannot be nested - POSTGRESQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58400246/

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