Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
HECTOR CORELLA
Starting Member
2 Posts |
Posted - 2008-02-21 : 23:20:16
|
Hey guys, here's what I have.I have a table thats structured as.datehourValuetagNameThe data has 2 diferent tag names, one of them is X the other a Y. I'm trying to build a query that would give a result asdate time valueoftagnameX valueoftagnameYThe data is collected every hour (60 values 1 per minute) and then the value is averaged for each of the tag.The resulting table is something like thisexample: 10/01/2007 10 45.4526 PR456710/01/2007 11 425.536 FR426710/01/2007 10 45.4526 PR456710/01/2007 11 421.36 FR4267I've tried a UNION query with aliases but the result is not what I'm looking for. One row has the X value, the next the Y value and so on.See what you think.Appreciate the helpHC |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-21 : 23:29:18
|
Hope this what you are looking for:-SELECT date,hour, SUM(CASE WHEN tagName='PR4567' THEN value ELSE 0 END) AS PR4567value, SUM(CASE WHEN tagName='FR4267' THEN value ELSE 0 END) AS FR4267valueFROM YourTableGROUP BY date,hour |
 |
|
HECTOR CORELLA
Starting Member
2 Posts |
Posted - 2008-02-22 : 11:13:36
|
With a little tweaking got it to work. Thank youvisakh16quote: Originally posted by visakh16 Hope this what you are looking for:-SELECT date,hour, SUM(CASE WHEN tagName='PR4567' THEN value ELSE 0 END) AS PR4567value, SUM(CASE WHEN tagName='FR4267' THEN value ELSE 0 END) AS FR4267valueFROM YourTableGROUP BY date,hour
|
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-22 : 11:22:19
|
quote: Originally posted by HECTOR CORELLA With a little tweaking got it to work. Thank youvisakh16quote: Originally posted by visakh16 Hope this what you are looking for:-SELECT date,hour, SUM(CASE WHEN tagName='PR4567' THEN value ELSE 0 END) AS PR4567value, SUM(CASE WHEN tagName='FR4267' THEN value ELSE 0 END) AS FR4267valueFROM YourTableGROUP BY date,hour
You are welcome |
 |
|
|
|
|
|
|