选择具有特定范围sql查询的行

时间:2012-10-09 07:33:52

标签: mysql sql

我有一张如下表格。

存储学生详细信息。

我想要一个SQL查询让学生姓名在15到27岁之间。

CREATE TABLE Students(Sno       INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
                      Name      VARCHAR(255),
                      Age_Start INT,
                      Grade     VARCHAR(255));


INSERT INTO Students(Name, Age_Start, Grade)
              VALUES('Student 1', 10, 'Grade A'),
                    ('Student 2', 15, 'Grade B'),
                    ('Student 3', 18, 'Grade C'),
                    ('Student 4', 21, 'Grade D'),
                    ('Student 5', 24, 'Grade E'),
                    ('Student 5', 27, 'Grade F'),
                    ('Student 5', 30, 'Grade G');

输出

{{1}}

先谢谢

2 个答案:

答案 0 :(得分:1)

select distinct Name as `Students Name`
 from Students
where Age_Start between 15 and 27


SQL Fiddle demo

答案 1 :(得分:1)

Select distinct Name as `Students Name` 
from Students 
where Age_Start between 15 and 27