whitetiger
whitetiger

Reputation: 75

How to query Google Sheets by a column's value through Sheets API?

This is what my spreadsheet looks like - (In reality, it would have more than 10,000 rows)

sample sheet

The For Class column is my kind-of main column, and as you can see it can also have multiple appearances of a particular value (like rows #3, #5, #8 & #10 have class = 7). By using the Google Sheets API (https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get) I have till now managed to get the whole data (I set the range to just Sheet1 & majorDimension to ROWS, and in result it returned me all my ~10,000 rows).

But what I am aiming to do is, just get all rows that have a specific For Class value (let's say, 7.) For example, if I were to run that command on my above sample snippet (with the For Class query value set to 7), I would get the rows 3, 5, 8 & 10. Is there any way I can achieve this through API?

Any help would be appreciated! Thanks a lot! 😀


P.S. I have tried creating another sheet, adding a formula to it, so it would give me my desired result of all rows with class = 7. - It works, but I might have 100s of users accessing this sheet at any given time, & they would have different values to query with. So, creating a new sheet for filtered results isn't suitable for me...

Upvotes: 0

Views: 2361

Answers (1)

sid
sid

Reputation: 2027

Per the docs, correct approach is

var query = new google.visualization.Query(DATA_SOURCE_URL);
query.setQuery('select dept, sum(salary) group by dept');
query.send(handleQueryResponse);

References:

  1. https://developers.google.com/chart/interactive/docs/querylanguage
  2. https://support.google.com/docs/answer/3093343?hl=en&ref_topic=9054531

Upvotes: 1

Related Questions