4

如何在第一个字符是数字的表中找到字符串?

我正在使用 MySQL LIKE 如下

SELECT   DISTINCT label_no_country
FROM     releases
WHERE    label_no_country LIKE '$letter%'  
ORDER BY label_no_country

AZ之间的字母在哪里$letter(取决于输入)

因此,如果$letter == 'A'这样,它将显示第一个字母为 A 的所有条目。

如何运行此查询以显示以数字开头的记录?

例如

1st record

干杯!

4

2 回答 2

26

您可能想使用正则表达式:

SELECT DISTINCT label_no_country FROM releases 
WHERE label_no_country 
REGEXP '^[0-9]'

有关详细信息,请参阅MySQL 文档

于 2012-06-15T12:59:14.160 回答
0
WHERE label_no_country >= '0' AND label_no_country <= '9zzzzzzzzzzzzz' -- Insert as many z:s as the field can hold

编辑: 或者更好的是,只需在整理序列中放入 9 之后的字符:

WHERE label_no_country >= '0' AND label_no_country < ':' -- assuming : is the character after 9 in your collating sequence
于 2012-06-15T12:59:43.770 回答