Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Pivot to display age span

$
0
0

Hi!

I have a task to create a pivot table but i am not familiar on how this works.

My customer wants to have a pivottable that contains countries in a row and ages and gender in the columns.

The query would output something like this.

Country Male Female 0-1 1-2 2-3 3+

Bolivia    1     2         2      0   0     1
Kenya     2    0          0     1           1

I have a table with countries, that i join to another table with children, in the child table the date of birth field exists.

Perhaps this is better to do without a pivot and calculate and insert data to a temporary table and then output it using select.

Any hint on how to do this is greatly appreciated.

Regards
Martin


Viewing all articles
Browse latest Browse all 23857

Trending Articles