问题
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.
- How to order by SUM(H)?
- 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