作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 MySQL 中有以下表格。(我正在使用 php/mysql)
CREATE TABLE `hw_subjects` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ;
...
INSERT INTO `hw_subjects` VALUES(4, 'Design');
INSERT INTO `hw_subjects` VALUES(5, 'Drama');
...
INSERT INTO `hw_subjects` VALUES(11, 'Humanities');
...
INSERT INTO `hw_subjects` VALUES(13, 'Mathematics');
...
following shows students missed homework
CREATE TABLE `hw_homeworkmissed` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`studentid` int(10) NOT NULL,
`subjectid` int(10) NOT NULL,
`assignment_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`teacherid` int(10) NOT NULL,
`date` datetime NOT NULL,
PRIMARY KEY (`id`)
) ;
INSERT INTO `hw_homeworkmissed` VALUES(1, 29, 5, '5E', 20, '2012-10-18 13:58:40');
INSERT INTO `hw_homeworkmissed` VALUES(2, 15, 5, '32B', 20, '2012-10-18 13:59:54');
INSERT INTO `hw_homeworkmissed` VALUES(3, 29, 4, 'Q2A', 20, '2012-10-18 17:53:46');
INSERT INTO `hw_homeworkmissed` VALUES(4, 29, 11, '6E', 20, '2012-10-02 20:06:39');
INSERT INTO `hw_homeworkmissed` VALUES(5, 29, 11, 'C15', 20, '2012-10-16 20:06:30');
INSERT INTO `hw_homeworkmissed` VALUES(6, 15, 11, '7A', 20, '2012-09-19 20:08:05');
INSERT INTO `hw_homeworkmissed` VALUES(7, 29, 5, '3B', 20, '2012-09-14 20:08:12');
INSERT INTO `hw_homeworkmissed` VALUES(8, 29, 13, '6E', 32, '2012-10-18 20:23:46');
...
我想显示一个学生(假设 studentid ==29)错过了作业。所以我需要科目和每个科目中错过的作业总数。 (我正在使用谷歌图表)
Mathematics,3
Science, 1
Humanities, 2
etc.
我该怎么做?提前致谢。
更新:
我可以获得以下数组。但是我不确定我是否可以使用它。我加入了 studentid =29 的两个表
Array
(
[0] => Array
(
[id] => 5
[studentid] => 29
[subjectid] => 5
[assignment_name] => 5E
[teacherid] => 20
[date] => 2012-10-18 13:58:40
[name] => Drama
)
[1] => Array
(
[id] => 4
[studentid] => 29
[subjectid] => 4
[assignment_name] => Q2A
[teacherid] => 20
[date] => 2012-10-18 17:53:46
[name] => Design
)
[2] => Array
(
[id] => 11
[studentid] => 29
[subjectid] => 11
[assignment_name] => 6E
[teacherid] => 20
[date] => 2012-10-02 20:06:39
[name] => Humanities
)
[3] => Array
(
[id] => 11
[studentid] => 29
[subjectid] => 11
[assignment_name] => C15
[teacherid] => 20
[date] => 2012-10-16 20:06:30
[name] => Humanities
)
[4] => Array
(
[id] => 5
[studentid] => 29
[subjectid] => 5
[assignment_name] => 3B
[teacherid] => 20
[date] => 2012-09-14 20:08:12
[name] => Drama
)
[5] => Array
(
[id] => 13
[studentid] => 29
[subjectid] => 13
[assignment_name] => 6E
[teacherid] => 32
[date] => 2012-10-18 20:23:46
[name] => Mathematics
)
)
....
....
最佳答案
在您的 SELECT 和 GROUP BY subjectid 中使用 COUNT(id)
SELECT
hw_subjects.name,
COUNT(hw_homeworkmissed.id)
FROM hw_subjects, hw_homeworkmissed
WHERE hw_subjects.id= hw_homeworkmissed.subjectid
GROUP BY subjectid
ORDER BY hw_subjects.name
关于php - 如何从 MySQL/PHP 中获取每个科目的科目名称和错过的作业总数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12954929/
我无法在附加行中显示“真”、“假”、"is"和“否”按钮。 我在这里有一个应用程序:Application 请按照以下步骤使用应用程序: 1。当你打开应用程序时,你会看到一个绿色的加号按钮,点击 在此
我是一名优秀的程序员,十分优秀!