想知道这些客户第一次下单是在第几周
如截图,在第一次下单的周数这里,客户A应该是返回WK3, 客户B返回WK2,请问使用SQL的话,有什么方法可以做到呢?
select
customer_name
, case
when wk1 is not null then 'wk1'
when wk2 is not null then 'wk2'
when wk3 is not null then 'wk3'
when wk4 is not null then 'wk4'
when wk5 is not null then 'wk5'
when wk6 is not null then 'wk6'
when wk7 is not null then 'wk7'
end as type from table_name
用coalesce函数
select coalesce(wk1,wk2,wk3,wk4,wk5,wk6,wk7,wk8,wk9,wk10) from 表