例如,我在数据库中有这个名字
LastName
Amy
Betty
Camy
Daisy
David
Johnson
只有在想要从Amy选择到David时才有效:
select * from Student
where LastName >= 'A' and LastName <= char(ascii('D') + 1)
order by LastName
如果我只想选择从Amy到Daisy,我将如何做?
答案 0 :(得分:2)
(我可能遗漏了你忘记在你的问题中包含的内容,但是)为什么要让生活变得更加艰难:
SELECT *
FROM Student
WHERE LastName BETWEEN 'Amy' AND 'Daisy'
ORDER BY LastName
要回复评论,您可以采取以下方式:
SELECT *
FROM Student
WHERE LastName >= 'Amy'
AND (LastName <= 'Dai' OR LastName LIKE 'Dai%')
SQL Fiddle证明这仍然会导致单个索引搜索。