我有一长串公司名称,但我只想要结果集只返回以字母 AE 开头的公司的结果。
那可能吗?
尝试使用LIKE
SELECT *
FROM tableName
WHERE CompanyName LIKE 'A%' OR
CompanyName LIKE 'B%' OR
CompanyName LIKE 'C%' OR
CompanyName LIKE 'D%' OR
CompanyName LIKE 'E%'
或正则表达式
SELECT *
FROM tableName
WHERE CompanyName REGEXP '^[A-E]';
其他)
您可以(也)使用简单的字符串比较来做到这一点;
SELECT *
FROM Companies
WHERE CompanyName >= 'a'
AND CompanyName < 'f'; -- to be sure to get _all_ companies on 'E'
Company names starting with A
, E
using LEFT
. If you need ending with then you can use RIGHT
as well.
SELECT *
FROM YOURTABLE
WHERE LEFT(CompanyName,1) IN ('A', 'E')
;
SELECT name FROM TABLE_NAME WHERE name BETWEEN 'a' AND 'e'
或者
SELECT Name FROM Employees WHERE Name REGEXP '^[A-E].*$'
SELECT * FROM mytable WHERE company_name < 'F';