sql - Combine multiple rows in table into 1 resultset row -


I have a table that stores this type of record:

  names | State | Price -------------------------- Item 1 | Stat1 | Val1 object1 | Stat2 | Val2 object1 | State 3 | Val3 object1 | Stat4 | Val4  

But I would like to query the data so that it will return such lines

  name. STAT1 | STAT2 | Stat3 | Stat4 ------------------------------------- object1 | Val1 | Val 2 Val3 | Val4  

Will I use case statement, or how will I accomplish such a thing? My example only shows 4 possible figures, but hopefully I can make something dynamic, where I add new figures in the future, the query will not be rewritten if this is not possible, what are my options?

typical pivot query:

  SELECT t.name, MAX ( CASE WHEN T. STAT = 'STAT1' THEN T. value ELSE NULL END) AS stat1, MAX (case when T. STAT = 'stat2' THEN t.value ELSE NULL END) AS State 2, Max (case when T.STAT = 'State3' then T. value ELSE Null & AS) State 3, Max (Case when T.Stat = 'State4' then T. value ales null & T) by T. T. Group from AS State 4 t.name  code> 

these values ​​need to be allocated statically, if you want to Area to handle the dynamic situation - to use dynamic SQL, this query should be changed in the dynamic SQL ...


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -