gpt4 book ai didi

SQL 服务器 : GROUP BY datetime without ticks

转载 作者:行者123 更新时间:2023-12-02 08:51:22 25 4
gpt4 key购买 nike

我有一个查询,它返回所有条目,带有唯一的 datetime 和刻度:

select t.date, count(*) as Count
from table t
group by t.date having count(*) = 1

我需要一个查询,该查询将返回具有唯一 datetime 且不带刻度的条目。要获取不带刻度的 datetime,我正在使用:

select CONVERT(VARCHAR(19), t.date, 120), count(*) as Count
from table t

所以我希望使用查询:

select CONVERT(VARCHAR(19), t.date, 120), count(*) as Count
from table t
group by CONVERT(VARCHAR(19), t.date, 120) having count(*) = 1

但是它抛出一个错误:

Column "table.date" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.

您知道我应该使用什么查询吗?

最佳答案

每个组中有多个可能的 datetime 值,所以不是

ORDER BY t.date

你可以使用,例如

ORDER BY MIN(t.date)

避免这个错误。

关于SQL 服务器 : GROUP BY datetime without ticks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8324117/

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