Does any one know how to create crosstab queries in PostgreSQL? For example I have the following table: Section Status Count A Active 1 A Inactive 2 B Active 4...
I tried to search posts, but I only found solutions for SQL Server/Access. I need a solution in MySQL (5.X). I have a table (called history) with 3 columns: hostid, itemname, itemvalue. If I do a sel...
I have a table that looks like this: id feh bar 1 10 A 2 20 A 3 3 B 4 4 B 5 5 C 6 6 D 7 7 D 8 8 D And I want it to look l...
Has anyone used tablefunc to pivot on multiple variables as opposed to only using row name? The documentation notes: The "extra" columns are expected to be the same for all rows with the same r...
I have the following table, which gives multiple email addresses for each user. I need to flatten this out to columns on a user query. To give me the "newest" 3 email addresses based on the creatio...
I am trying to create crosstab queries in PostgreSQL such that it automatically generates the crosstab columns instead of hardcoding it. I have written a function that dynamically generates the column...
Suppose I have a table in Postgres called listings that looks like this: id neighborhood bedrooms price 1 downtown 0 256888 2 downtown 1 334000 3 ...
I have a table named as Product: create table product ( ProductNumber varchar(10), ProductName varchar(10), SalesQuantity int, Salescountry varchar(10) ); Sample values: insert i...
I have a table and want to transpose its rows to columns, similar to a pivot table but without summarising. For example I have the following tables: Question --QuestionID --QuestionText Response --...
I implemented this function in my Postgres database: http://www.cureffi.org/2013/03/19/automatically-creating-pivot-table-column-names-in-postgresql/ Here's the function: create or replace function ...