Invalid count and sum in cross tab query using PostgreSQL
I am using PostgreSQL 9.3 version database. I have a situation where I want to count the number of products sales and sum the amount of product and also want to show the cities in a column where the product have sale. Example Setup create table products ( name varchar(20), price integer, city varchar(20) ); insert into products values ('P1',1200,'London'), ('P1',100,'Melborun'), ('P1',1400,'Moscow'), ('P2',1560,'Munich'), ('P2',2300,'Shunghai'), ('P2',3000,'Dubai'); Crosstab query : select * from crosstab ( 'select name,count(*),sum(price),city,count(city) from products group by name,city