All Questions

128
votes
5answers
100213 views

PostgreSQL Crosstab Query

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...
113
votes
10answers
142536 views

MySQL - Rows to Columns

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...
20
votes
5answers
20101 views

Dynamic alternative to pivot with CASE and GROUP BY

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...
9
votes
3answers
17181 views

Pivot on Multiple Columns using Tablefunc

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...
19
votes
2answers
46315 views

Postgres - Transpose Rows to Columns

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...
11
votes
3answers
14004 views

Dynamically generate columns for crosstab in PostgreSQL

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...
8
votes
1answers
33638 views

Create a pivot table with PostgreSQL

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 ...
2
votes
1answers
6894 views

Dynamic pivot query using PostgreSQL 9.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...
1
votes
2answers
13940 views

SQL Rows to Columns

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 --...
5
votes
2answers
2021 views

Execute a dynamic crosstab query

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 ...

Previous Next