how to choose which row to insert with same id in sql?

后端 未结 4 1607
深忆病人
深忆病人 2021-01-26 21:07

so Basically I have a table called \"table_1\" :

ID   Index          STATUS          TIME        DESCRIPTION
1     15          pending           1:00       Start         


        
4条回答
  •  再見小時候
    2021-01-26 21:26

    INSERT INTO myTable2 (ID, STATUS, TIME, DESCRIPTION)
    SELECT t1.ID, t1.STATUS, t1.TIME, t1.DESCRIPTION FROM table_1 as t1 
    WHERE STATUS = 'complete' 
    OR TIME = (SELECT min(TIME) FROM table_1 WHERE ID = t1.ID) 
    ORDER BY ID asc, STATUS desc
    

提交回复
热议问题