简体   繁体   中英

Convert sql query to hql

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;

Can anyone give me the hql query for this?

If you are not acquainted with the HQL and want to use the same query ,then you can do it using the native query feature of the Hibernate like this :

@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)

But I would recommend that you first try to convert the same in into HQL query and then if any issue then you should ask it here instead of directly asking for the converted query. Meanwhile this can help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM