用sql如何求下面的值
mysql 的a表a字段
如下 
1-ererer
1sdf-erer
232-fff
6c-erer
.....
通过sql需要得到如下
ererer
erer
fff
erer也即使需要找到出现第一个-  的位置,之后把他后面的值给取出来

解决方案 »

  1.   

    SUBSTRING_INDEX(str,delim,count) Returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. SUBSTRING_INDEX() performs a case-sensitive match when searching for delim. mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2);
            -> 'www.mysql'
    mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2);
            -> 'mysql.com'
      

  2.   

    mysql> select * from t_liyihongcug;
    +-----------+
    | a         |
    +-----------+
    | 1-ererer  |
    | 1sdf-erer |
    | 232-fff   |
    | 6c-erer   |
    +-----------+
    4 rows in set (0.00 sec)mysql> select SUBSTRING_INDEX(a,'-',-1) from t_liyihongcug;
    +---------------------------+
    | SUBSTRING_INDEX(a,'-',-1) |
    +---------------------------+
    | ererer                    |
    | erer                      |
    | fff                       |
    | erer                      |
    +---------------------------+
    4 rows in set (0.00 sec)mysql>
      

  3.   

    情况有变化1-...ererer
    1sdf-666erer
    232-,,.fff
    6c-,,,,erer
    .....
    通过sql需要得到如下
    ererer
    erer
    fff
    erer 
    取各个字段值里以 字母开头后的值。 
    如上