Solved Can this be done in SQL?

April 30, 2012 at 18:22:14
Specs: N/A
I'm trying to manipulate some data so that i can determine how many companies in our database have different country classifications between our different financial products (different products have different rules which make us classify companies differently).

each row of this table i am working with in SQL is company based. the table is unique on our internal identifier ("symbol") and the product code (product_id). so there can be multiple MSFT's in the table but only one MSFT in product 211 for example.

anyway, i'm trying to determine which companies have different country classifications ("p_ctrycode") between the products they are in. if a company is constant across the board (most will be) then i don't want it in my results.

in addition to knowing which companies have different classifications i would also like to know what classifications are in which products for the ones that differ.

i've never encountered this issue before - it seems like i need to re-map/restructure product_id to be the column names (maybe?) or something to that extent.

it's kind of driving me nuts. any help would be appreciated.

thanks in advance.

See More: Can this be done in SQL?

Report •

May 1, 2012 at 07:14:44
✔ Best Answer
for anyone interested, one of the IT guys at work gave me the answer because the request was time sensitive.

on one side i'm upset i couldn't figure it out. on the other hand, i'm glad he gave it to me because it was a little above my knowledge/skill level as far as SQL goes, so i never would have figured it out.

here's what he gave me (and it worked perfectly):

;WITH cte AS(SELECT DISTINCT symbol,P_CtryCode
FROM dbo.Component_2012
WHERE tradate = '20120430')

FROM dbo.Component_2012
WHERE tradate = '20120430'
FROM cte
GROUP BY symbol

Report •
Related Solutions

Ask Question