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 |
|
seenhzj
Starting Member
8 Posts |
Posted - 2011-06-13 : 21:40:01
|
| Hello, I have a master table likeCityName, Month, TemperatureA,Jan,20....A,Dec,1B,Jan,30....Z,December,12I would like to generate a differentiation table likeiCity,jCity,Month,DifferentTemperatureA, B, Jan, a.temperature-b.temperature...A, Z,Dec, a. temperature-z.temperature.....each row would loop through the rest row on a particular month in the master table. What is the best way to do that? How did you come up an idea to solve this problem?Thank you very much!Learning to master T-SQL |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-06-13 : 21:49:20
|
[code]select c1.CityName, c2.CityName, c1.[Month], DifferentTemperature = c1.Temperature - c2.Temperaturefrom master c1 inner join master c2 on c1.[Month] = c2.[Month] and c1.CityName < c2.CityNameorder by c1.CityName, c2.CityName[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
seenhzj
Starting Member
8 Posts |
Posted - 2011-06-13 : 22:12:32
|
quote: Originally posted by khtan
select c1.CityName, c2.CityName, c1.[Month], DifferentTemperature = c1.Temperature - c2.Temperaturefrom master c1 inner join master c2 on c1.[Month] = c2.[Month] and c1.CityName < c2.CityNameorder by c1.CityName, c2.CityName KH[spoiler]Time is always against us[/spoiler]
It looks very good! Thank you very much!Learning to master T-SQL |
 |
|
|
|
|
|
|
|