|
andrewcw
Posting Yak Master
USA
129 Posts |
Posted - 08/13/2012 : 17:45:59
|
Several weeks ago I was introduced to a way to move data into columns - Xvalues were alternating with Yvalues by row This is an example of that effort.
SELECT C_FKEY,LN,attempt, MAX(CASE WHEN Seq=1 THEN Stream_FKey END) AS X_Fkey, 'INDEPX' as IndepTransducer, MAX(CASE WHEN Seq=1 THEN Value END) AS Xvalue, MAX(CASE WHEN Seq=2 THEN Stream_FKey END) AS Y_Fkey,'SENSOR_Y' as Transducer, MAX(CASE WHEN Seq=2 THEN Value END) AS Yvalue, recordNum FROM (SELECT ROW_NUMBER() OVER (PARTITION BY C_FKEY, attempt,recordNum ORDER BY stream_fkey) AS Seq,* FROM ( Select * from [SILK].[dbo].[TestFlightStreamHistory] where LN between 4130 and 4260 and ( Stream_FKey = 5259 or Stream_FKey = 5260) ) dtable )t GROUP BY LN,C_FKEY,Attempt, RecordNum
I dont understand the SELECT ROW_NUMBER() OVER (PARTITION BY C_FKEY, attempt,recordNum ORDER BY stream_fkey) AS Seq,* very well.
If I have a series of stream_fkeys that belong to the X-values & Y-values - then is there something else I can do, other than reduce my data to each X,Y pair and append the data as each set processes ?
In the above example - 5259 was for the X-Values, 5260 for Y-values. Sometimes I will get more pairs, say 6443 for X-values, and 6448 for Y-values, and etc.
Can select row_number() over partition by applied in this way or do I need to process each pair of stream_keys.
Thanks
andrewcw |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
48119 Posts |
Posted - 08/13/2012 : 18:00:46
|
unless you provide us some data and explain we will not be able to understand your scenario well From what I understood I think what you need is field which indicates mapping between corresponding X and Y values (5259->5260,6443->6448,...) do you've such a field?
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|