I need to turn the following SQL results into a pivot table
I don't beleieve an aggregate function will help with this one.
The query is simplified for the purpose of this post.
I have used the SQL 2005 PIVOT operator to show columns of aggregated data.
However, I'm not sure how to turn the following SQL results into a pivot table.
Any help/suggestions would be appreciated.
Thanks!
Chris
============
The SQL:
============
============
The results:
============
============
What I need:
============
I don't beleieve an aggregate function will help with this one.
The query is simplified for the purpose of this post.
I have used the SQL 2005 PIVOT operator to show columns of aggregated data.
However, I'm not sure how to turn the following SQL results into a pivot table.
Any help/suggestions would be appreciated.
Thanks!
Chris
============
The SQL:
============
Code:
SELECT p.user_id, pit.data_name, pi.item_value
FROM profile p
JOIN profile_item pi ON pi.profile_id = p.profile_id
JOIN profile_item_type pit ON pit.profile_item_type_id = pi.profile_item_type_id
AND pit.data_name in ('age','gender','marital_status','family_size','household_income','ethnicity')
WHERE p.user_id = 100
The results:
============
Code:
p.user_id pit.data_name pi.item_value
--------- ------------- -------------
100 age Under 18
100 gender Male
100 marital_status Single
100 family_size 1
100 household_income Under $15,000
100 ethnicity Rather not disclose
What I need:
============
Code:
p.user_id age gender marital_status family_size household_income ethnicity
--------- --- ------ -------------- ----------- ---------------- ---------
100 Under 18 Male Single 1 Under $15,000 Rather not disclose