SQL 标头和详细报告的策略

发布于 2024-09-17 19:51:10 字数 388 浏览 5 评论 0原文

我想从mysql school 表中获取所有学校,并在students 表中获取每个学校的所有学生。带有标题和总计的基于网络的报告。我可以做类似

select * from schools join Students on schoolNo = schoolNo order by schoolNo

但是这样我想我必须跟踪当前的 schoolNo 并与以前的 schoolNo 进行比较,以便为每个新的生成标题和学生总数学校。

或者,我可以对学校进行选择,并对找到的每所学校的学生进行额外选择。这更直观,但看起来效率很低。

mySQL 是否提供了更好的技术来解决这个问题,例如专业的报告工具(如水晶报告)。

谢谢

I want to get all schools from the mysql school table and get all students of each school in the students table. for a web based report with heading and totals. I could do something like

select * from schools join students on schoolNo = schoolNo order by schoolNo

Howwever this way I think I will have to keep track of current schoolNo and compare with previous schoolNo in order to generate a header and student count totals for each new school.

Alternatively I could do a Select on Schools and additional selects on students for each school found. This is more intuitive but looks very inefficient.

Does mySQL offer a better techniques fot this like specialized reporting tools like Crystal reports.

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

混吃等死 2024-09-24 19:51:10

您想要一份包含学生人数的学校列表吗?

select sc.*, (select count(st.*) from students st where st.schoolNo = sc.schoolNo) as students from schools sc;

注意:您应该在学生表中的 schoolNo 上放置一个索引。

You want a list of schools with number of students?

select sc.*, (select count(st.*) from students st where st.schoolNo = sc.schoolNo) as students from schools sc;

NB: You should put an index on schoolNo in students table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文