MK Shrimper
Striker
...as requested. Apologies if this is the dullest thread on SZ ever......:zzzzz:
use NetworkRail
go
select wcs.imdm as [IMDM],wcs.Day,wcs.Month,wcs.Year,
sum(wcs.maxT*rat.RATIO) as [Weighted_Max Temp],sum(wcs.minT*rat.RATIO) as [Weighted_Min Temp],sum(wcs.maxw*rat.ratio) as [Weighted_WindGust],
sum(wcs.MaxPr*rat.RATIO) as [Weighted_Precipitation],sum(wcs.maxsnow*rat.ratio) as [Weighted_Snowfall]
from
(
SELECT im.[WeatherCell],im.IMDM
,datepart(day,[DateTime]) as [Day]
,datepart(month,[DateTime]) as [Month]
,datepart(YEAR,[DateTime]) as [Year]
,max(Temperature) as MaxT
,min(Temperature) as MinT
,max(WindGust) as MaxW
,sum(TotalPrecipitation) as MaxPr
,sum(Snowfall) as MaxSnow
FROM [NetworkRail].[dbo].[Weather] as wt
inner join IMDMWeatherCellMap as im
on im.WeatherCell=wt.WeatherCell
where wt.DateTime>='2017-04-02 00:00:00'
group by im.weathercell,imdm,datepart(DAY,wt.DateTime),datepart(month,wt.datetime),datepart(year,wt.datetime)
) as wcs
inner join
(
SELECT t1.IMDM,t1.WeatherCell,T1.TrackLength/TTL.TTL AS RATIO FROM
(
SELECT WC.[WeatherCell]
,IM.IMDM
,[TrackLength]
FROM [NetworkRail].[dbo].[WeatherCellProperties] AS WC
INNER JOIN IMDMWeatherCellMap AS IM
ON IM.WeatherCell=WC.WeatherCell
) T1
INNER JOIN TTL
ON TTL.IMDM = T1.IMDM
) as rat
on wcs.WeatherCell=rat.WeatherCell and wcs.IMDM=rat.IMDM
group by wcs.IMDM,
wcs.Day,wcs.Month,wcs.Year
order by wcs.IMDM,wcs.[year],wcs.[month],wcs.[day]
use NetworkRail
go
select wcs.imdm as [IMDM],wcs.Day,wcs.Month,wcs.Year,
sum(wcs.maxT*rat.RATIO) as [Weighted_Max Temp],sum(wcs.minT*rat.RATIO) as [Weighted_Min Temp],sum(wcs.maxw*rat.ratio) as [Weighted_WindGust],
sum(wcs.MaxPr*rat.RATIO) as [Weighted_Precipitation],sum(wcs.maxsnow*rat.ratio) as [Weighted_Snowfall]
from
(
SELECT im.[WeatherCell],im.IMDM
,datepart(day,[DateTime]) as [Day]
,datepart(month,[DateTime]) as [Month]
,datepart(YEAR,[DateTime]) as [Year]
,max(Temperature) as MaxT
,min(Temperature) as MinT
,max(WindGust) as MaxW
,sum(TotalPrecipitation) as MaxPr
,sum(Snowfall) as MaxSnow
FROM [NetworkRail].[dbo].[Weather] as wt
inner join IMDMWeatherCellMap as im
on im.WeatherCell=wt.WeatherCell
where wt.DateTime>='2017-04-02 00:00:00'
group by im.weathercell,imdm,datepart(DAY,wt.DateTime),datepart(month,wt.datetime),datepart(year,wt.datetime)
) as wcs
inner join
(
SELECT t1.IMDM,t1.WeatherCell,T1.TrackLength/TTL.TTL AS RATIO FROM
(
SELECT WC.[WeatherCell]
,IM.IMDM
,[TrackLength]
FROM [NetworkRail].[dbo].[WeatherCellProperties] AS WC
INNER JOIN IMDMWeatherCellMap AS IM
ON IM.WeatherCell=WC.WeatherCell
) T1
INNER JOIN TTL
ON TTL.IMDM = T1.IMDM
) as rat
on wcs.WeatherCell=rat.WeatherCell and wcs.IMDM=rat.IMDM
group by wcs.IMDM,
wcs.Day,wcs.Month,wcs.Year
order by wcs.IMDM,wcs.[year],wcs.[month],wcs.[day]