SELECT recipe.name,SUM(salesdetails.quantity::integer),recipe.price As Quantity
FROM (salesinfo JOIN salesdetails ON salesinfo.sessionid=salesdetails.salesinfo_sessionid)
JOIN recipe ON salesdetails.recipe_id=recipe.id group by salesdetails.recipe_id,recipe.name,recipe.price
ORDER BY SUM(salesdetails.quantity::integer) DESC;


谁能给我这个hql查询吗?

最佳答案

如果您不熟悉HQL并想使用相同的查询,则可以使用Hibernate的本机查询功能来做到这一点,如下所示:

@QUERY(value="SELECT recipe.name, SUM(salesdetails.quantity::
INTEGER),recipe.price AS Quantity
FROM (salesinfo
JOIN salesdetails ON salesinfo.sessionid=salesdetails.salesinfo_sessionid)
JOIN recipe ON salesdetails.recipe_id=recipe.id
GROUP BY salesdetails.recipe_id,recipe.name,recipe.price
ORDER BY SUM(salesdetails.quantity:: INTEGER) DESC", nativeQuery = TRUE)


但是,我建议您首先尝试将其转换为HQL查询,然后如果有任何问题,则应在此处询问,而不是直接询问转换后的查询。同时,这可以有所帮助。

关于java - 将SQL查询转换为HQL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45475177/

10-12 05:44