3

我有一长串公司名称,但我只想要结果集只返回以字母 AE 开头的公司的结果。

那可能吗?

4

5 回答 5

4

尝试使用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]';

其他)

于 2013-01-21T07:07:34.303 回答
2

您可以(也)使用简单的字符串比较来做到这一点;

SELECT *
FROM Companies 
WHERE CompanyName >= 'a'  
  AND CompanyName <  'f';  -- to be sure to get _all_ companies on 'E' 

简单的 SQLfiddle

于 2013-01-21T07:10:19.153 回答
1

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')
;
于 2013-01-21T07:21:04.177 回答
1
SELECT name FROM TABLE_NAME WHERE name BETWEEN 'a' AND 'e'

或者

SELECT Name FROM Employees WHERE Name REGEXP '^[A-E].*$'
于 2014-05-08T08:29:42.660 回答
0
SELECT * FROM mytable WHERE company_name < 'F';
于 2013-01-21T07:09:44.277 回答