Monday, March 21, 2016

[google-cloud-sql-discuss] Re: Pivoting result set

Thanks for posting your question here.

You are correct that you would not need use an aggregate function. However, what you seek to accomplish has some caveats. The data set you propose shows no limit to the number of companies a Original Company / Person Name may be a part of. If, one may be a board member of 21 companies, your result set would need to have the 21 additional columns to summarize said memberships. Accomplishing this with a single query may be possible but will be terribly inefficient and error. It's also not a recommended practice with SQL to turn rows into columns which is essentially what is requested with the 'Member of Board' data set column.

If this must be accomplished, you may be able to accomplish this with using cursors to iterate through your data set and upsert to your resulting table. Unfortunately, data relationships like these are often better represented by data systems like BigQuery which allows repeated records or Datastore which has repeated properties.

I hope this helps.

On Wednesday, March 16, 2016 at 2:56:32 PM UTC-4, Victor Chirinian wrote:
Hello Everyone,

I was asked to do a report and wanted to pivot the result set to mirror the destination format below. I don't think i need to use an aggregate function, and I am having a hard time navigating through existing reference material online. The goal is to have the first two columns of the second table be unique, and the third column broken down into individual columns. Any help would be appreciated, thank you!


Orignal Company Person NameMember of Board
     
Company DJohn Doe Company A
Company DJohn Doe Company B
Company DJohn Doe Company C
Orignal CompanyPerson Name Board 1 Board 2Board 3
     
Company DJohn Doe Company ACompany B Company C 

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/2082c4a2-1f81-4a0a-a361-904a52911775%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment