Re: [SQL] crosstab category mix - Mailing list pgsql-sql

From Steve Midgley
Subject Re: [SQL] crosstab category mix
Date
Msg-id CAJexoSKHupKeUK1UFwOkgHUi_NYEmRax_6+L6EbRj_jmvr2p5Q@mail.gmail.com
Whole thread Raw
In response to [SQL] crosstab category mix  (Majid Khan <mk.swati@gmail.com>)
List pgsql-sql


On Jun 12, 2017 12:53 AM, "Majid Khan" <mk.swati@gmail.com> wrote:
Hi,

I have a query returning me three columns 'Date', 'District' and 'Total'. There are four districts but some time a district may not have record for corresponding date. I want to put all my districts in column and their total in rows as ..

Date, District1, District2, District3, District4

While in my rows will be date along with the total value per district.

I am using crosstab to get the desired results. But in the result total for one district is listed in other district though the datewise grand total is same.

I don't know why crosstab query mixes categories. Please help.

Regards,
Majid

Please provide sample data and sql to allow us to see where your problem is. 

Steve 

pgsql-sql by date:

Previous
From: Majid Khan
Date:
Subject: [SQL] crosstab category mix
Next
From: Majid Khan
Date:
Subject: Fwd: Re: [SQL] crosstab category mix