我试图在分组时获取表中列的值,这是我的基本查询
SELECT
category,
COUNT (value)
FROM
parameters
GROUP BY
category
这将使我得到值的计数,但是是否也可以得到值?这就是我现在得到的 -
finance 7
law 2
science 5
这就是我要的 -
finance 7 [{],{},{]...]
law 2 [{],{}]
science 5 [{],{},{]...]
sequelize 和 Postgres 有可能吗?我真的很感激任何帮助,谢谢,为了进一步澄清我的观点,我想要按列(类别)分组的数据,所以原始数据是这样的 -
[
{
"id": "uuid",
"category": "law",
"value": {},
},
{
"id": "uuid",
"category": "science",
"value": {},
},
{
"id": "uuid",
"category": "law",
"value": {},
},
{
"id": "uuid",
"category": "science",
"value": {},
},
{
"id": "uuid",
"category": "finance",
"value": {},
},
...
]
我希望他们像这样分组-
[
{
"category": "law",
"value": [{ all the values with category law}],
},
{
"category": "science",
"value": [{ all the values with category science }],
},
{
"category": "finance",
"value": [{ all the values with category finance }],
},
...
]
Postgres和sequelize可以做到这一点吗?