Compare values of timestamps and assign a value to each of them in case they have changed

前端 未结 2 866
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-22 09:10

DB-Fiddle

CREATE TABLE operations (
    id int auto_increment primary key,
    time_stamp DATE,
    product VARCHAR(255),
    plan_week VARCHAR(2         


        
2条回答
  •  青春惊慌失措
    2021-01-22 09:47

    I would just use window functions:

    select o.*,
           (case when min(plan_week) over (partition by product) = max(plan_week) over (partition by product)
                 then 'no' else 'yes'
            end) as switched
    from operations o;
    

提交回复
热议问题