一个州有特定的商店
我需要显示每行所有商店的AVERAGE销售额。
select
tbl_Mill_FAS.Mill_Name,
tbl_Zone_FAS.Zone_Name,
tbl_Station.Station_Name,
tbl_Daily_Data.dValue,
AVG(tbl_Daily_Data.dValue)
from tbl_Mill_FAS
inner join tbl_Zone_FAS on tbl_Zone_FAS.Zone_Id = tbl_Mill_FAS.Zone_Id
inner join tbl_Station on tbl_Station.Station_Id = tbl_Mill_FAS.Station_Id
inner join tbl_Daily_Data on tbl_Daily_Data.Daily_Id = tbl_Mill_FAS.Daily_Id
group by
tbl_Mill_FAS.Mill_Name,
tbl_Zone_FAS.Zone_Name,
tbl_Station.Station_Name,
tbl_Daily_Data.dValue
State - Pongola
Store1 - Mass Mart - Sales: $4000 - Avg: $1669
Store2 - Wallmart - Sales: $333 - Avg: $1669
Store3 - CNN - Sales: $674 - Avg: $1669
答案 0 :(得分:0)
select
tbl_Mill_FAS.Mill_Name,
tbl_Zone_FAS.Zone_Name,
tbl_Station.Station_Name,
tbl_Daily_Data.dValue,
AVG(tbl_Daily_Data.dValue),
AVG(tbl_Daily_Data.dValue) over (partition by tbl_Mill_FAS.Mill_Name)
from tbl_Mill_FAS
inner join tbl_Zone_FAS on tbl_Zone_FAS.Zone_Id = tbl_Mill_FAS.Zone_Id
inner join tbl_Station on tbl_Station.Station_Id = tbl_Mill_FAS.Station_Id
inner join tbl_Daily_Data on tbl_Daily_Data.Daily_Id = tbl_Mill_FAS.Daily_Id
group by
tbl_Mill_FAS.Mill_Name,
tbl_Zone_FAS.Zone_Name,
tbl_Station.Station_Name,
tbl_Daily_Data.dValue