google bigquery - Get MAX from row with column name (SQL) -
sorry if questin simple, spent 1 day googling , still can't figure out how solve this:
i have table like:
userid b c d e 1 5 0 2 3 2 2 3 2 0 7 3 and need each max per row column name:
userid max 1 2 d all ideas appreciated! thanks! use google big query possibilities different form mysql understand, try translate if have ideas in mysql way.
you can use greatest:
select userid, case greatest(a,b,c,d,e) when 'a' when b 'b' when c 'c' when d 'd' when e 'e' end max tablename result:
userid max 1 2 d with sample table looks like:
select userid, case greatest(a,b,c,d,e) when 'a' when b 'b' when c 'c' when d 'd' when e 'e' end max (select 1 userid, 5 a, 0 b, 2 c, 3 d, 2 e), (select 2 userid, 3 a, 2 b, 0 c, 7 d, 3 e)
Comments
Post a Comment