我的SQL Select语句中的语法错误?

时间:2016-11-07 21:02:03

标签: sql ms-access syntax-error inner-join

在没有between的情况下收到错误说明and运营商,但我有一个and,所以我不明白。提前谢谢

Syntax Error

A picture of the question

select 
    a.student_name, a.test_score, b.letter_grade
from 
     sec1311_student_scores a 
inner join
     sec1311_grade_ranges b on a.testscore between b.beginning_score and b.endingscore
order by 
    a.student_name;

2 个答案:

答案 0 :(得分:2)

Access不支持join子句中的BETWEEN。来自the documentation

FROM table1 INNER JOIN table2 ON table1.field1 compopr table2.field2
The INNER JOIN operation has these parts:

Part           | Description 
----           | -------------
table1, table2 | The names of the tables from which records are combined.
field1, field2 | The names of the fields that are joined. If they are not numeric, the fields must be of the same data type and contain the same kind of data, but they do not have to have the same name.
compopr        | Any relational comparison operator: "=," "<," ">," "<=," ">=," or "<>."

但是,您可以指定多个加入条件,因此您应该可以这样做:

select 
    a.student_name, a.test_score, b.letter_grade
from 
     sec1311_student_scores a 
inner join
     sec1311_grade_ranges b on a.testscore >= b.beginning_score 
                        and on a.testscore <= b.endingscore
order by 
    a.student_name;

答案 1 :(得分:1)

试试这个:

select 
    a.student_name, a.test_score, b.letter_grade
from 
    sec1311_student_scores as a, 
    sec1311_grade_ranges as b 
where
    a.testscore between b.beginning_score and b.ending_score
order by 
    a.student_name;