Google sheets query order by SUM

对着背影说爱祢 提交于 2021-02-11 15:19:11

问题


I am trying to do this query:

=query(indirect($B$1), "select D, E, F, SUM(H) group by D,E,F pivot G order by SUM(H)",1)

It looks OK, but results in an error:

Unable to parse query string for Function QUERY parameter 2: NO_AGG_IN_ORDER_WHEN_PIVOT: H If I try

=query(indirect($B$1), "select D, E, F, SUM(H) group by D,E,F pivot G order by H",1) the I get: 

Unable to parse query string for Function QUERY parameter 2: COL_IN_ORDER_MUST_BE_IN_SELECT: H

=query(indirect($B$1), "select D, E, F, SUM(H) group by D,E,F pivot G order by D",1) works OK.  
  1. How to order by SUM(H)?
  2. Any idea how to order by SUM(H) for specific value of G (like in Pivot table in google sheets)?

回答1:


You can't use ORDER BY and PIVOT at the same time. But you can use 2 query nested functions. In the first one using PIVOT and the second one with the ORDER BY.

Remmember that in the second query you must use de Col1, Col2, ... notation:

=query(query(indirect($B$1)
             , "select D, E, F, SUM(H) 
                group by D, E, F 
                pivot G"
             , 1)
       , "select *
          ORDER BY Col4"
       , 1) 


来源:https://stackoverflow.com/questions/54987920/google-sheets-query-order-by-sum

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!