SQL How to remove duplicates within select query?

前端 未结 7 759
甜味超标
甜味超标 2021-01-04 07:05

I have a table which looks like that:

\"alt

As You see, there are some date duplicates, so how t

7条回答
  •  借酒劲吻你
    2021-01-04 07:14

    You mention that there are date duplicates, but it appears they're quite unique down to the precision of seconds.

    Can you clarify what precision of date you start considering dates duplicate - day, hour, minute?

    In any case, you'll probably want to floor your datetime field. You didn't indicate which field is preferred when removing duplicates, so this query will prefer the last name in alphabetical order.

     SELECT MAX(owner_name), 
            --floored to the second
            dateadd(second,datediff(second,'2000-01-01',start_date),'2000-01-01') AS StartDate
     From   MyTable
     GROUP BY dateadd(second,datediff(second,'2000-01-01',start_date),'2000-01-01')
    

提交回复
热议问题