考虑下表:
create table mixedvalues (value varchar(50));
insert into mixedvalues values ('100');
insert into mixedvalues values ('ABC100');
insert into mixedvalues values ('200');
insert into mixedvalues values ('ABC200');
insert into mixedvalues values ('300');
insert into mixedvalues values ('ABC300');
insert into mixedvalues values ('400');
insert into mixedvalues values ('ABC400');
insert into mixedvalues values ('500');
insert into mixedvalues values ('ABC500');
如何编写一个只返回数字值的select语句,如
100
200
300
400
500
答案 0 :(得分:72)
SELECT *
FROM mixedvalues
WHERE value REGEXP '^[0-9]+$';
答案 1 :(得分:4)
答案 2 :(得分:4)
SELECT *
FROM mixedvalues
WHERE concat('',value * 1) = value;
答案 3 :(得分:1)
列表项的字符串以数字开头
$string = "Test";
select * from table where columnname REGEXP "$string-*[0-9]+";
答案 4 :(得分:0)
SELECT * FROM mixedvalues
WHERE value > 0
ORDER BY CAST(value as SIGNED INTEGER) ASC
答案 5 :(得分:-3)
您可以使用ISNUMERIC
功能过滤结果集:
SELECT value
FROM #mixedvalues
where ISNUMERIC(value)=1