Tuesday, March 27, 2012

Create a table of temperature

Hello,

I don't know how to make this :

1 table containing list of cities
1 table containing date and temperature

both linked by IdCity

how can i create a table to display cities in rows, date in colums and temperature at intersections ?

Thanks !Hi,

as I get to know you, you want to join two tables. To do this you can use JOIN, RIGHT JOIN, LEFT JOIN in your SQL Statement.

it woul look like this ".... JOIN Cities ON Cieties.IdCity=Temperatures.IdCity
....."

look here for more about joins:
http://www.w3schools.com/sql/sql_join.asp|||Please take a look at the pivot operator in Books Online. You can generate the cross-tab type of report using that. This however requires knowing the values of date since that needs to be used in the pivot clause. ex:

select crp.CityName, crp.[20050101], crp.[20050102]
from Cities as c
join CityReadings as cr
on c.IdCity = cr.IdCity
pivot (max(cr.temperature) for cr.date in ([20050101], [20050102])) as crp
order by crp.CityName;
|||Ok but Pivot only works with SQL2K5 not with SQL2K ?sql

No comments:

Post a Comment