我正在使用POSTGRESQL和sequelize.js,并且真的想执行一个看起来像这样的查询
SELECT "CT_Foo"."cola", "CT_Foo"."colb", "CT_Foo"."colc",
"CT_Foo"."cold", "CT_Foo"."cole", "CT_Foo"."colf",
COUNT(*)
FROM (
SELECT "CT_BAR"."cola", "CT_BAR"."colb", "CT_BAR"."colc",
"CT_BAR"."cold", "CT_BAR"."cole", "CT_BAR"."colf",
"CT_BAR"."colg"
FROM public."Customers" AS "CT_BAR"
WHERE ("CT_BAR"."colf" IN ('SOMEID') AND "CT_BAR"."colg" ?
'date')
) AS "CT_Foo"
WHERE ("CT_Foo"."colf" IN ('SOMEID'))
GROUP BY "CT_Foo"."cola", "CT_Foo"."colb", "CT_Foo"."colc",
"CT_Foo"."cold", "CT_Foo"."cole", "CT_Foo"."colf"
列A-F是文本,G是JSONB
基本上我之所以这样做是因为我需要在列F上对列F进行分组,如果列G中的JSONB中存在某些内容,我不希望在分组中包含列G,因为它是JSON,我正在检查是否存在日期......这似乎是一种简单的方法。我知道postgresql有CTE,但是sequelize不支持它们。我相信另一个名字是" Derived Tables"
我可以正常形成查询,但不能将子查询带入FROM子句。
有关如何做到这一点或获得相同结果的任何想法?