编写SQL查询以查找已注册某个位置提供的单元的学生? [英] Write the SQL query to find students who are enrolled for units offered in a location?
问题描述
问题表我认为这三个表都将被使用.但是我无法建立一个表Student_1
和Course
之间的关系.
Problem Table " I think for this all three tables will be used. But I can't establish a relation between table Student_1
and Course
.
@ APC该代码有效,但是只给2个学生而不是3个学生,我的桌子上有什么错误吗? 课程表 学生_2表 学生_1 来自@APC代码的答案
@ APCThis code is working.But giving only 2 students instead of 3, is there any mistake in my table?. Course table student_2 table Student_1 Answer from @APC code
推荐答案
对于学生ID,未选择任何行"
"for student id one no row selected "
计算机非常精确.他们将完全按照您编写的代码运行代码.您的查询具有以下WHERE子句:
Computers are extremely precise. They will run the code exactly as you write it. Your query has this WHERE clause:
location like '%burwood%'
但是,如果仔细查看course
中的数据,您会发现location
中的值是Burwood
. 'Burwood'
不等于'burwood'
,因为前导字母的情况有所不同.
But if you look carefully at the data in course
you will spot that the value in location
is Burwood
. 'Burwood'
does not equal 'burwood'
because of that difference in the case of the leading letter.
如果您这样编写WHERE子句,您将获得结果:
You would have gotten results if you had written your WHERE clause like this:
location like '%urwood%'
但是,最好使用相等过滤器进行过滤:
However it is always better to filter with an equality filter:
select s1.student_id
, s1.student_fname
, s1.student_fname
, c.course
from course c
join student2 s2 on s2.course_id = c.course_id
join student1 s1 on s1.student_id = s2.student_id
where c.location = 'Burwood';
这篇关于编写SQL查询以查找已注册某个位置提供的单元的学生?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!