如何在 mysql table 中按特定年份过滤特定课程?

how to filter specific course by specific year in one mysql table?

我在一个网站上锻炼,该网站要求我仅在一个 table 中按年份显示特定课程。

这是我的 table 的一些详细信息:

Table学生

stdID、stdCourseDesc、访问日期

12211, 飞机维修许可证程序?欧洲航空安全局第 66 部分,2018-3-6

12212, 飞机维修许可证程序?欧洲航空安全局第 66 部分,2015-8-6

12213, 飞机维修技术文凭(制造), 2017-3-1

12214, 工商管理硕士(创业学), 2018-1-16

12215, 飞机维修许可证程序?欧洲航空安全局第 66 部分,2015-10-1

12216, 飞机维修许可证程序?欧洲航空安全局第 66 部分,2016-12-10

12217, 哲学博士(制造), 2016-5-14

在此之前我只能设法编码,但当然它只显示课程。

SELECT CONCAT(`stdCourseDesc`, ', ', `accessDate`) AS byYear FROM student WHERE `stdCourseDesc` = 'Aircraft Maintenance License Program ? EASA Part 66'

我试过了但是失败了。

SELECT CONCAT(stdCourseDesc, ', ', accessDate) AS byYear FROM student where `stdCourseDesc` = 'Aircraft Maintenance License Program ? EASA Part 66', YEAR(`accessDate`)=2015

我将使用这段代码来显示输出

$conn = new mysqli ('localhost', 'root', '', 'dashboard');

$aircraftyear2015 = $conn ->query ("SELECT CONCAT(`stdCourseDesc`, ', ', 
`accessDate`) AS byYear FROM student WHERE `stdCourseDesc` = 'Aircraft 
Maintenance License Program ? EASA Part 66'");
$aircraftyear2016 = $conn ->query ("SELECT CONCAT(`stdCourseDesc`, ', ', 
`accessDate`) AS byYear FROM student WHERE `stdCourseDesc` = 'Aircraft 
Maintenance License Program ? EASA Part 66'");
$aircraftyear2017 = $conn ->query ("SELECT CONCAT(`stdCourseDesc`, ', ', 
`accessDate`) AS byYear FROM student WHERE `stdCourseDesc` = 'Aircraft 
Maintenance License Program ? EASA Part 66'");
$aircraftyear2018 = $conn ->query ("SELECT CONCAT(`stdCourseDesc`, ', ', 
`accessDate`) AS byYear FROM student WHERE `stdCourseDesc` = 'Aircraft 
Maintenance License Program ? EASA Part 66'");

$tot_aircraftyear2015 = mysqli_num_rows($aircraftyear2016);
$tot_aircraftyear2016 = mysqli_num_rows($aircraftyear2017);
$tot_aircraftyear2017 = mysqli_num_rows($aircraftyear2016);
$tot_aircraftyear2018 = mysqli_num_rows($aircraftyear2017);

<?php echo $tot_aircraftyear2015; ?>
<?php echo $tot_aircraftyear2016; ?>
<?php echo $tot_aircraftyear2017; ?>
<?php echo $tot_aircraftyear2018; ?>

我要如何按特定年份过滤特定课程 mysql table?

我的代码可以用来显示数据吗? 提前谢谢你

看起来可能是语法问题,请尝试以下操作:

SELECT CONCAT(stdCourseDesc, ', ', accessDate) AS byYear 
FROM student 
WHERE  `stdCourseDesc` = 'Aircraft Maintenance License Program ? EASA Part 66' 
  AND YEAR(`accessDate`) = '2015'