以下是查询
SELECT omt.actualendtime::date,
(SELECT array_to_json(array_agg(row_to_json(t)))
FROM (SELECT odt.productshortname,
count(odt.*)
FROM orderdetail_runtime_tran odt
WHERE odt.actualendtime::date = omt.actualendtime::date
AND odt.stagename = 'Ironing'
GROUP BY odt.productshortname
) t
) as item_current_count
From orderdetail_runtime_tran omt
WHERE omt.actualendtime IS NOT NULL AND date_part('year', omt.actualendtime) = '2019'
AND omt.stagename = 'Ironing'
GROUP BY omt.actualendtime::date;
此查询给出了错误
子查询使用外部查询中未分组的列“ omt.actualendtime”
答案 0 :(得分:0)
尝试使用子查询:
SELECT actualenddate,
(SELECT array_to_json(array_agg(row_to_json(t)))
FROM (SELECT odt.productshortname, count(odt.*)
FROM orderdetail_runtime_tran odt
WHERE odt.actualendtime::date = actualenddate AND
odt.stagename = 'Ironing'
GROUP BY odt.productshortname
) t
) as item_current_count
FROM (SELECT omt.*,
omt.actualendtime::date as actualenddate
FROM orderdetail_runtime_tran omt
WHERE omt.actualendtime IS NOT NULL AND
date_part('year', omt.actualendtime) = '2019' AND
omt.stagename = 'Ironing'
) omt
GROUP BY actualenddate;