Re: [NOVICE] group by rollup and cube - Mailing list pgsql-novice

From Laurenz Albe
Subject Re: [NOVICE] group by rollup and cube
Date
Msg-id 1510817247.2639.20.camel@cybertec.at
Whole thread Raw
In response to [NOVICE] group by rollup and cube  (john snow <ofbizfanster@gmail.com>)
List pgsql-novice
john snow wrote:
> i'm trying to learn how to do these from these examples that i found in:
> 
> https://www.databasejournal.com/features/mssql/using-the-rollup-cube-and-grouping-sets-operators.html
> 
> after modifying the code to run in postgresql 10, i'm finding that even though
> i'm getting subtotal and grand total values same as those in the article,
> i'm not quite getting the report rows in the desired orders.

A query result has no guaranteed ordering unless you specify
one with an ORDER BY clause.

ORDER BY is executed after the grouping, so you can use it to
sort the result rows.

You'll have to come up with an ORDER BY clause that puts the
result in the desired order.

The NULLS LAST clause will help in some of your cases.
For example, for your first question I'd use
  ORDER BY type NULLS LAST

to put the summary line at the bottom.

Yours,
Laurenz Albe


-- 
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

pgsql-novice by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: [NOVICE] How to get n records from parent table and theirchildren
Next
From: Dean Montgomery
Date:
Subject: [NOVICE] ERROR: expected one dependency record for TOAST table, found 0