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

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

    you could get all the start times like this:

       select id, status, min(time) 
       from table_1 
       where status = 'Pending'
       group by id, status
    

    then completion like this:

       select id, status, time
       from table_1 
       where status = 'Complete'
       group by id, status
    

    you can use union to use both, and of course try:

       insert into table_2
    

提交回复
热议问题