QUERY syntax using cell reference

后端 未结 8 1506
隐瞒了意图╮
隐瞒了意图╮ 2020-12-23 21:46

I\'m having trouble figuring out a fairly simple QUERY statement in Google Spreadsheets. I\'m trying to use a cell reference instead of static values and I\'m running into t

相关标签:
8条回答
  • 2020-12-23 21:49

    I know this is an old thread but I had the same question as the OP and found the answer:

    You are nearly there, the way you can include cell references in query language is to wrap the entire thing in speech marks. Because the whole query is written in speech marks you will need to alternate between ' and " as shown below.

    What you would need is this:

    =QUERY(Responses!B1:I, "Select B where G contains '"& B1 &"' ")
    

    If you then wanted to refer to multiple cells you could add more like this

    =QUERY(Responses!B1:I, "Select B where G contains '"& B1 &"' and G contains '"& B2 &"' ")
    

    The above would filter down your results further based on the contents of B1 and B2.

    0 讨论(0)
  • 2020-12-23 21:54

    To make it work with both text and numbers:

    Exact match:

    =query(D:E,"select * where D like '"&C1&"'", 0)
    

    Convert search string to lowercase:

    =query(D:E,"select * where D like lower('"&C1&"')", 0)
    

    Convert to lowercase and contain part of the search string:

    =query(D:E,"select * where D like lower('%"&C1&"%')", 0)
    

    A1                = query/formula
    yellow / A:B  = result area
    green / C1    = search area
    blue / D:E     = data area

    If you get error when the input is text and not numbers; move the data and delete the (now empty) columns. Then move the data back.

    0 讨论(0)
  • 2020-12-23 21:57

    I found out that single quote > double quote > wrapped in ampersands did work. So, for me it looks like this:

    =QUERY('Youth Conference Registration'!C:Y,"select C where Y = '"&A1&"'", 0)
    
    0 讨论(0)
  • 2020-12-23 21:57

    none of the above answers worked for me. This one did:

    =QUERY(Copy!A1:AP, "select AP, E, F, AO where AP="&E1&" ",1)

    0 讨论(0)
  • 2020-12-23 22:06

    Here is working code: =QUERY(Sheet1!$A1:$B581, "select B where A = '"&A1&"'")

    In this scenario I needed the interval to stay fixed and the reference value to change when I drag it.

    0 讨论(0)
  • 2020-12-23 22:08

    Copied from Web Applications:

    =QUERY(Responses!B1:I, "Select B where G contains '"&$B1&"'")
    
    0 讨论(0)
提交回复
热议问题