如何在mysql的括号内获取确切的字符串

时间:2013-11-07 08:39:22

标签: mysql

在我的mysql表中,字段值如下:

    table name - "clients"                        
    field name - "accent"   
    values are - "Eastern(Northern,Southern),Scottish(East Coast)"
                 "Eastern(South,North,Southern),Scottish(East Coast)"

如果我给 select accent from clients where accent like '%north%'

如果超过100个记录不在同一个订单中。括号内的字符串的顺序不同。

它将给出以上两个值。 我怎么才能获得第二个价值?

请帮帮我,谢谢。

3 个答案:

答案 0 :(得分:0)

试试这个

select accent from clients where accent like '%North,%'

<强>更新

如果您只想选择North not Northern,请尝试使用

select accent from clients where accent like '%North%' and accent not like '%Northern%'

如果您只想要Northern值,请尝试使用

select accent from clients where accent like '%Northern%'

希望这可以解决您的问题。

答案 1 :(得分:0)

试试这个:

select accent from clients where accent regexp 'North[^a-z]'

正则表达式意味着匹配包含“北”的所有内容,而不包含其他字母

答案 2 :(得分:0)

您可以使用偏移属性。

select accent from clients where accent like '%north%' limit 1 offset 1

其中limit表示您只检索一个记录,offset表示从第二个项目开始。