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

后端 未结 4 1606
深忆病人
深忆病人 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:22

    INSERT INTO table_2
    SELECT id,status,min(time)
    FROM table_1 AS t1
    WHERE EXISTS(SELECT 1
                 FROM table_1
                 WHERE id=t1.id
                     AND status='complete')
    GROUP BY id,status
    

    I think that should do it for you, haven't tested it though :(

提交回复
热议问题