简体   繁体   English

从休眠中使用多个表中获取计数?

[英]get count from using multiple tables in Hibernate?

In my Sql have...4 tables like.. 在我的SQL中有... 4个表..

classtable
sid     date    timetableid
ct1      -       tt1
ct2      -       tt2
ct3     --       tt3

and my Timetable 和我的Timetable

sid    startDate   skillsetid
tt1      ---        ss1
tt2      ---        ss1
tt3      ---        ss2

and my Skillset 和我的Skillset

sid     courseid
ss1        c1
ss2        c2

and finally my Course table. 最后是我的Course表。

sid    name
c1     java
c2     flex

Finally my requirement is count the no.of courses.. using Classtable 最后,我的要求是使用Classtable计算课程的数量。

for example according to above tables 2-java and 1-flex so these count will be displayed on my html page like 2(java) or 4(flex)..etc .. what ever we get the count... so please suggest me how to get count and display on html.. 例如根据上面的表格2-java1-flex因此这些计数将显示在我的html页面上,例如2(java)或4(flex).. etc ..无论我们得到什么计数...所以请建议我如何获得计数并显示在html上。

Join your tables and group the result: 加入表并将结果分组:

SELECT   Course.name, COUNT(*)
FROM     classtable
    JOIN Timetable ON Timetable.sid = classtable.timetableid
    JOIN Skillset  ON  Skillset.sid = Timetable.skillsetid
    JOIN Course    ON    Course.sid = Skillset.courseid
GROUP BY Course.sid

See it on sqlfiddle . sqlfiddle上看到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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