【发布时间】:2020-01-02 12:08:22
【问题描述】:
我需要从同一个表中检索两个不同的结果,并将它们组合成一个结果集。我正在使用聚合函数来生成一些数据的报告,并且每一列都有不同的“位置”条件。
select sum(price)
as lucro_esperado
from tasks
where extract(month from enddate) = 12
AND extract(year from enddate) = 2019
和
select count(*)
as tarefas_abertas
from tasks
where extract(month from date_added) = 12
AND extract(year from date_added) = 2019
由于我对这种情况感兴趣的是聚合函数结果,因此我无法使用 Join 语句(因为没有 ON 条件),Union 语句会抱怨不同的数据类型,因为它试图错误地将两个聚合结果合并到一个列中。有没有其他方法可以实现这一点,而不必从我的 Node.js 端点查询数据库两次,然后手动组合它们?
【问题讨论】:
标签: sql node.js postgresql express