简体   繁体   English

Google表格查询WHERE子句仅返回第一行数据

[英]Google Sheets Query WHERE clause just returns first row of data

I have a sheet which I am trying to use to show an overview of students results in a number of subjects, with each student and their results in separate rows. 我有一张工作表,试图用来显示许多学科的学生成绩概览,每个学生及其成绩都放在单独的行中。

OVERVIEW 概述

  • studentID, English, Maths, etc 学生ID,英语,数学等
  • 1, result1, result2, etc 1,result1,result2等
  • 2, result3, result4, etc 2,result3,result4等

The result data comes from another system and is in a separate sheet. 结果数据来自另一个系统,位于单独的工作表中。 Each result for each subject is a separate row where the first column is the student ID, the second is the subject and the third is the result. 每个主题的每个结果都是单独的一行,其中第一列是学生ID,第二列是主题,第三列是结果。

RESULTSET 结果集

  • 1, ENGLISH, result 1 1,英语,结果1
  • 1, MATHS, result 2 1,MATHS,结果2
  • etc. 等等

I've been trying various forms of a query like this =query(RESULTSET!A1:C,"SELECT C WHERE A = '1' AND B = 'ENGLISH'",1) but the query only ever returns the first result from the first row of data in RESULTSET. 我一直在尝试各种形式的查询,例如=query(RESULTSET!A1:C,"SELECT C WHERE A = '1' AND B = 'ENGLISH'",1)但该查询只返回了第一个结果RESULTSET中的第一行数据。

Here is a link to a test spreadsheet containing data and queries that reproduces the issue: https://docs.google.com/spreadsheets/d/15xLAyHumL2pC8mRfA4Qs9xMyrWZvK86kmoi2kBWnB34/edit?usp=sharing 以下是指向包含该问题的数据和查询的测试电子表格的链接: https : //docs.google.com/spreadsheets/d/15xLAyHumL2pC8mRfA4Qs9xMyrWZvK86kmoi2kBWNB34/edit?usp=sharing

I am expecting to see results from the result set that matches each student ID and subject, but I am only ever seeing the first result irrespective of ID or subject. 我期望从结果集中看到与每个学生ID和科目匹配的结果,但是我只会看到第一个结果,而不论ID或科目如何。

Remove the single quotes around the reference to column A and set the headers argument in query() to zero. 删除对A列的引用周围的单引号,并将query()中的headers参数设置为零。 In B2 try 在B2中尝试

=iferror(query('result set 1'!$A$1:$C58,"SELECT C WHERE A = "&$A2&" AND B = '"&UPPER(B$1)&"'",0))

Fill down to the right and down as far as needed and see if that works? 根据需要向右下方填充,看看是否可行?

Another option would be to use in B2 另一种选择是在B2中使用

=ArrayFormula(iferror(vlookup($A$2:$A$8&B$1, {'result set 1'!$A:$A&'result set 1'!$B:$B, 'result set 1'!$C:$C}, 2, 0)))

and fill to the right (make sure there is no data below row 2). 并填充到右侧(确保第2行下方没有数据)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM