我有像这样的mysql数据库
id | code
1 | bok-1
2 | bok-2
3 | bok-3
4 | inv-1
5 | inv-2
6 | inv-3
如何获取前缀bok-
的最新数量?
上面示例中的代码结果为bok-3
答案 0 :(得分:2)
这有效:
select code
from Table1
where code like "bok%"
order by cast(substring(code from 5) as signed) desc
limit 1
编辑:
如果列表中有bok-11,它现在给bok-11,因为我认为11大于3。答案 1 :(得分:0)
代码尝试:
select code from table where id in (select max(id) where code like 'bok-%');
仅限id:
select max(id) where code like 'bok-%'