Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a "sort" to a =QUERY statement in Google Spreadsheets

Tags:

I've setup a simple =QUERY statement that will pull targeted rows/columns out of a 'response' sheet and put them into a topic specific sheet.

=QUERY(responses!A1:K; "Select C, D, E where B contains '2nd Web Design' ") 

What I looking for is a way to "automatically sort" the rows being pulled by two methods.

  1. Alpha sort rows by one column
  2. Date/time sort rows by one column

Any suggestions on how I can modify the above QUERY to automatically sort the rows?

like image 277
Mr. B Avatar asked Feb 01 '14 02:02

Mr. B


People also ask

How do I sort data in a Google spreadsheet query?

Google Sheets Query: ORDER BY (ascending or descending) Within Google Sheets QUERY, you can sort data across columns in ascending (ASC) or descending (DESC) order using the ORDER BY clause.

How do I create a sort rule in Google Sheets?

Advanced range sorting options.If your columns have titles, click Data has header row. Select the column you'd like to be sorted first and choose a sorting order. To add another sorting rule, click Add another sort column.


1 Answers

You can use ORDER BY clause to sort data rows by values in columns. Something like

=QUERY(responses!A1:K; "Select C, D, E where B contains '2nd Web Design' Order By C, D") 

If you’d like to order by some columns descending, others ascending, you can add desc/asc, ie:

=QUERY(responses!A1:K; "Select C, D, E where B contains '2nd Web Design' Order By C desc, D") 
like image 104
Pankaj Jaju Avatar answered Oct 15 '22 17:10

Pankaj Jaju