The PIVOT syntax converts row data into columnar data, and vice versa for the UNPIVOT syntax. Not all databases support the PIVOT syntax but the functionality can be implemented, often using decision logic (CASE statements, etc) and aggregate functions.
61
votes
9answers
105k views
SQL Server PIVOT examples?
Trying to find some simple SQL Server PIVOT examples. Most of the examples that I have found involve counting or summing up numbers. I just want to pivot some string data. For example, I have a ...
32
votes
4answers
32k views
TSQL Pivot without aggregate function
I have a table like this...
CustomerID DBColumnName Data
--------------------------------------
1 FirstName Joe
1 MiddleName S
1 LastName Smith
1 ...
25
votes
12answers
106k views
How can I combine multiple rows into a comma-delimited list in Oracle?
I have a simple query:
select * from countries
with the following results:
country_name
------------
Albania
Andorra
Antigua
.....
I would like to return the results in one row, so like this:
...
20
votes
10answers
7k views
JavaScript/HTML5 equivalent of Microsoft Pivot?
Is there any similar JS/HTML5 library for generating visualizations like Microsoft Pivot? I love the software but I don't like the idea of embedding SilverLight on page to use it. I have been looking ...
19
votes
7answers
17k views
How to pivot a MySQL entity-attribute-value schema
I need to design tables which stores all the metadata of files (i.e., file name, author, title, date created), and custom metadata (which has been added to files by users, e.g. CustUseBy, CustSendBy). ...
18
votes
1answer
20k views
MySQL pivot table
If I have a MySQL table looking something like this:
company_name action pagecount
-------------------------------
Company A PRINT 3
Company A PRINT 2
Company A PRINT 3
Company B ...
13
votes
8answers
16k views
SQL Server 2005 Pivot on Unknown Number of Columns
I am working with a set of data that looks something like the following.
StudentName | AssignmentName | Grade
---------------------------------------
StudentA | Assignment 1 | 100
StudentA ...
12
votes
4answers
13k views
SQL Transpose Rows as Columns
I have an interesting conundrum which I believe can be solved in purely SQL. I have tables similar to the following:
responses:
user_id | question_id | body
----------------------------
1 | 1 ...
12
votes
4answers
6k views
How to pivot rows into columns (custom pivoting)
I have a Sql Database table similar to the following:
Day Period Subject
Mon 1 Ch
Mon 2 Ph
Mon 3 Mth
Mon 4 CS
Mon 5 Lab1
Mon 6 Lab2
...
12
votes
4answers
3k views
DataBound Pivot control is not creating the first PivotItem
In a Windows Phone 7 page I have the following control:
<controls:Pivot x:Name="Pivoter" Title="{Binding Name}"
TitleTemplate="{StaticResource PivotTitleTemplate}"
...
10
votes
4answers
9k 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
...
10
votes
2answers
15k views
SQL Server PIVOT - Multiple Aggregates
Given the following result set:
---------------------------------------------------------
CustomerID Service TransType SubTotal Tax NetTotal
...
10
votes
2answers
10k views
Pivot Table and Concatenate Columns
I have a database in the following format:
ID TYPE SUBTYPE COUNT MONTH
1 A Z 1 7/1/2008
1 A Z 3 7/1/2008
2 B C 2 ...
9
votes
1answer
11k views
SQL Server - Dynamic PIVOT Table - SQL Injection
Sorry for the long question but this contains all the SQL I've used to test the scenario to hopefully make it clear as to what I'm doing.
I'm build up some dynamic SQL to produce a PIVOT table in SQL ...
8
votes
3answers
134 views
Find count occurrences
I have a table with 2 columns (db: sql server 2008):
id name
----- ------
1 Bob
2 Mike
3 Mary
4 Mike
5 Barry
6 Benson
7 ...