SQL server Pivot Table issue -



SQL server Pivot Table issue -

i have table columns , values like:

records status custname amount 71 blocked customer_1 132171 11 booked customer_1 19974 3 cancelled customer_1 3900

i want write query info :

custname blocked_recs blocked_amount booked_recs booked_amount cancelled_recs cancelled_amount customer_1 71 132171 11 19974 3 3900

the problem pertains sql server 2008 r2

what should query exactly?

here how this:

select r1.c, r1.[blocked], r2.[blocked], r1.[booked], r2.[booked], r1.[cancelled], r2.[cancelled] from(select * (select r, c, s t) t pivot(max(r) s in([blocked],[booked],[cancelled]))p) r1 bring together (select * (select a, c, s t) t pivot(max(a) s in([blocked],[booked],[cancelled]))p) r2 on r1.c = r2.c

here fiddle http://sqlfiddle.com/#!6/acf78

sql-server pivot

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -