Thursday, 15 April 2010

sql - google spreadsheet query function column id other than letter of column -



sql - google spreadsheet query function column id other than letter of column -

alright... not sure if these done.

i'm in google spreadsheets cell a1 = time.. range a1:c4.

i have simple table follows:

time sit down stand 1 bob mike 2 fred pat 3 chris mike

this query:

=query($a$1:$c$4,"select a,b,c c='mike'",0)

... pretty straight forward. however, want column reference dynamic. need able query using header. how do it? i've tried following:

=query($a$1:$c$4,"select 'sit ', 'stand' 'stand' = 'mike' ",0) =query($a$1:$c$4,"select sit, stand stand = 'mike' ",0)

and per page's suggestion: google spreadsheet query error - column doesn't exist

i've tried following:

=query($a$1:$c$4,"select col2, col3 col3 = 'mike' ",0) =query($a$1:$c$4,"select col2, col3 (col3) = 'mike' ",0) =query($a$1:$c$4,"select (col2), (col3) (col3) = 'mike' ",0) =query($a$1:$c$4,"select 'col2', 'col3' 'col3' = 'mike' ",0)

none of them work... know how or know if possible?

https://developers.google.com/chart/interactive/docs/querylanguage

the examples here seems can it, app script only? , not in spreadsheet function?

unfortunately there no native way of referencing columns headers in query spreadsheet function select clause.

you can utilize colx notation if first argument of query other explicitly referenced range. 1 way accomplish wrap range in parentheses, , invoking arrayformula:

=arrayformula(query(($a$1:$c$4),"select col2, col3 col3 = 'mike'",0))

and rather ugly, can utilize match function bolt in header references:

=arrayformula(query(($a$1:$c$4),"select col"&match("sit";$a$1:$c$1;0)&", col"&match("stand";$a$1:$c$1;0)&" col"&match("stand";$a$1:$c$1;0)&" = 'mike'",1))

sql google-apps-script google-spreadsheet

No comments:

Post a Comment