我正在尝试截断日期,并按值分组。 我已经尝试过了:
var f = Collection.Find(Builders<Model>.Filter.And(defaultFilters));
f.Project<Model>(Builders<Model>.Projection.Exclude(m => m.Id);
var result = await f.FirstOrDefaultAsync();
我也尝试过按select v.sop, FUNC('DATE_TRUNC', 'day', v.scrappedAt) as dt, sum(v.totalValue)
from TABLE v
where v.coordStatus like 'done%' and (:plant is null or v.target =
:plant) and v.scrappedAt is not null
group by v.sop, dt
分组
FUNC
错误是相同的
org.postgresql.util.PSQLException: 错误:列“ t_mcp_verschrottungs_db_sharepoint.scrappedat” 必须出现在GROUP BY子句中或在聚合函数中使用
答案 0 :(得分:1)
严格来说,如果FUNC
是本机Postgres函数,则您的查询应该可以使用,并且该查询将符合ANSI。阅读this SO question后,似乎Postgres无法弄清楚两个FUNC
调用实际上是同一回事。也许您可以使用相关的子查询来重新计算总和:
SELECT
v1.sop,
FUNC('DATE_TRUNC', 'day', v1.scrappedAt) AS dt,
(SELECT SUM(totalValue) FROM TABLE v2
WHERE v2.sop = v1.sop AND
FUNC('DATE_TRUNC', 'day', v2.scrappedAt) =
FUNC('DATE_TRUNC', 'day', v1.scrappedAt) AND
v2.acoordStatus LIKE 'done%' AND
(:plant is null OR v2.target = :plant) AND
v2.scrappedAt IS NOT NULL) value_sum
FROM TABLE v1
WHERE
v1.coordStatus LIKE 'done%' AND
(:plant is null OR v1.target = :plant) AND
v1.scrappedAt IS NOT NULL;
如果上述方法不起作用或性能不佳,则可以使用本机Postgres查询。