使用映射键分组
Grouping by with a map key
我想对按键对结果进行分组的地图的值求和。我有以下查询。
SELECT b.foreignEntity.id, KEY(b.map), sum(VALUE(b.map))
FROM B b GROUP BY b.foreignEntity, KEY(b.map)
不幸的是,它的执行以以下运行时异常结束。
Column ?map1_.map_key? must appear in the group by clause or be used in an aggregate function
我尝试通过添加 AS
将查询更改为以下查询,但看起来 HQL
不明白我想要什么。
SELECT b.foreignEntity.id, KEY(b.map) AS group1, sum(VALUE(b.map))
FROM B b GROUP BY b.foreignEntity, group1
我在这种情况下得到的例外是
Column ?scoretype? does not exist.
如何使用 HQL
实现我想要的?底层数据库是 PostgreSQL。
奇怪,但是用地图属性加入实体解决了问题。
SELECT b.foreignEntity.id, KEY(m), sum(VALUE(m))
FROM B b JOIN b.map m GROUP BY b.foreignEntity, KEY(m)
我想对按键对结果进行分组的地图的值求和。我有以下查询。
SELECT b.foreignEntity.id, KEY(b.map), sum(VALUE(b.map))
FROM B b GROUP BY b.foreignEntity, KEY(b.map)
不幸的是,它的执行以以下运行时异常结束。
Column ?map1_.map_key? must appear in the group by clause or be used in an aggregate function
我尝试通过添加 AS
将查询更改为以下查询,但看起来 HQL
不明白我想要什么。
SELECT b.foreignEntity.id, KEY(b.map) AS group1, sum(VALUE(b.map))
FROM B b GROUP BY b.foreignEntity, group1
我在这种情况下得到的例外是
Column ?scoretype? does not exist.
如何使用 HQL
实现我想要的?底层数据库是 PostgreSQL。
奇怪,但是用地图属性加入实体解决了问题。
SELECT b.foreignEntity.id, KEY(m), sum(VALUE(m))
FROM B b JOIN b.map m GROUP BY b.foreignEntity, KEY(m)