0

I have the following result from my SQL query:

EventID          P_Num  PN_NameCount1   PN_Name
ABC-I-10942683  1089213     1            Company 1
ABC-I-10942683  1326624     8            Company 2

I am still learning this capability in SQL and need some assistance, Pivot's are NOT working in this scenario.

I have tried several different ways in attempting to do this, but was not able to create the desired results:

EventID          P_Num1     PNC1    PN_Name     PNC_Num2      PNC2  PN_Name
ABC-I-10942683  1089213     1       Company     11326624        8   Company 2

The EventID will change based on the different events from the companies, as the EventID is based on a particular date the event occurred with the company.

This is just a sample of the 500K+ rows of data I am working with. This will go into a temp table to be joined with the other various pieces of data needed.

I have tried this without success:

  SELECT Key, 
         MAX(Col1) AS Col1, 
         MAX(Col2) AS Col2, 
         MAX(Col3) AS Col3 
    FROM table 
GROUP BY Key
4

1 回答 1

0
select EventID 
, min(P_Num) as P_Num1, min(PN_NameCount1)  PNC1, min(PN_Name) as PN_Name1
, max(P_Num) as P_Num2, max(PN_NameCount1)  PNC2, max(PN_Name) as PN_Name2 
from table 
group by EventID  

这是对所述问题的回答。你在评论中说你可以扩展它。

于 2013-08-13T17:10:21.417 回答