[英]How to use Group By in seedstack?
I want to use Group By in Seedstack, to count lines and sum certain values. 我想在Seedstack中使用Group By来计数行并求和某些值。
eg : I have this table "employee" in database : 例如:我在数据库中有此表“ employee”:
id name section value
----------------------------
1 Chun DDE 5
2 Tom DMD 8
3 Diana DMD 18
4 Frisk DDE 2
5 Laura DVD 10
6 Chris DMD 15
And I need something like this equivalent in SQL: 我需要类似SQL的东西:
SELECT section, count(1) as staff, sum(value) as result FROM employee group by section;
section staff result
------------------------
DDE 2 7
DMD 3 41
DVD 1 10
What is the best way to do this in seedstack ? 在种子堆栈中执行此操作的最佳方法是什么?
SeedStack does its relational db access through the JPA or the JDBC standards: SeedStack通过JPA或JDBC标准进行关系数据库访问:
I recommend you to go the JPA route. 我建议您采用JPA路线。 You can learn how to configure and use it with SeedStack here: http://seedstack.org/guides/jpa 您可以在此处了解如何配置和使用SeedStack: http ://seedstack.org/guides/jpa
When using the business framework, persistence operations are encapsulated in repositories that you need to extend to go beyond built-in abilities. 使用业务框架时,持久性操作封装在存储库中 ,您需要扩展这些存储库以超越内置功能。 In a method of your custom repository you can use the full JPA API by obtaining the JPA EntityManager interface with getEntityManager()
. 在自定义存储库的一种方法中,可以通过使用getEntityManager()
获得JPA EntityManager接口来使用完整的JPA API。
As for the JPA equivalent to Group By, you have can use either the criteria API or the JPQL query language. 至于等同于Group By的JPA,您可以使用条件API或JPQL查询语言。 You can read this for more information: https://www.objectdb.com/java/jpa/query/jpql/group . 您可以阅读以下内容以获取更多信息: https : //www.objectdb.com/java/jpa/query/jpql/group 。
If you have JPA working fine, you can repost a more specific question with the JPA tag (regardless of using SeedStack or not). 如果您的JPA工作正常,则可以使用JPA标签重新发布一个更具体的问题(无论是否使用SeedStack)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.