删除mysql表中括号内的数据

时间:2016-02-28 17:28:38

标签: mysql

我有一个MySQL表,其客户字段包含括号中的一些数据。例如 -

客户

abstract class AbstractChange implements ChangeI {
    State state = State.READY ;

    public State getState() { return state ; }

    public void execute() {
        assert state == State.READY ;
        try { doHook() ; state = State.DONE ; }
        catch( Failure e ) { state = State.STUCK ; }
        catch( Throwable e ) { assert false ; }
    }

    public void undo() { 
        assert state == State.DONE ; }
        try { undoHook() ; state = State.UNDONE ; }
        catch( Failure e ) { state = State.STUCK ; }
        catch( Throwable e ) { assert false ; }
    }

    public void redo() {
        assert state == State.UNDONE ;
        try { redoHook() ; state = State.DONE ; }
        catch( Failure e ) { state = State.STUCK ; }
        catch( Throwable e ) { assert false ; }
    }

    protected abstract void doHook() throws Failure ; 

    protected abstract void undoHook() throws Failure ; 

    protected void redoHook() throws Failure { doHook() ;} ; 
}

有没有办法删除括号中的数据并使用SQL保留公司名称?

2 个答案:

答案 0 :(得分:0)

嗯。我看到了这些例子,你想要在第一次开放之前完成一切。您可以使用以下方式执行此操作:

select trim(substring_index(customer, '(', 1))

答案 1 :(得分:0)

Let's assuming that, if parenthesis in the company name, then

Query

select 
replace(customer, concat('(',substring_index(customer, '(', -1)), '') as new_col_name
from your_table_name;

SQL Fiddle demo