0

这个问题是我从 PHP mysql 面试测试中得到的。我想知道创建以下报告的最佳解决方案是什么。它看起来很简单,但有些东西。

这是我想要的两份报告的图片,请访问: 两份报告的图片

抱歉链接,因为我是 Stack Overflow 的新手,所以我无法上传图片。

如果需要,这里是 mysql 转储文件, exam.sql 文件

是的,有一个家庭作业,我创建了这两个报告,但我不太确定这是最好的方法。我没有发布我的努力,因为我希望有新的想法。这是他们的观点(在我的采访中)

条件:

  • 您必须动态创建这两个报告。
  • 您只能为这两个报告创建一个 PHP 脚本。
4

2 回答 2

0

You'll want to use the MySQL JOIN query to get the tables joined up in this way. Furthermore, for the second table, you need to use a GROUP BY modifier on top of that JOIN. The manual in the links should explain it all.

于 2012-07-02T12:28:42.833 回答
0

Learn about MySQL Joins. MySQL Joins

SELECT t1.user_fname AS FName, t1.user_lname AS LName, t2.subject AS Subject, t2.marks AS Marks FROM t_users AS t1 JOIN t_marks AS t2 ON t1.user_id = t2.user_id;

For Report A.

SELECT t1.user_fname AS FName, t1.user_lname AS LName, t2.subject AS Subject, SUM(t2.subject) AS Total FROM t_users AS t1 JOIN t_marks AS t2 ON t1.user_id = t2.user_id GROUP BY (t2.subject);

For Report B, I suppose it should work.

于 2012-07-02T12:29:37.540 回答