我有一个SQL Server查询,显示每个商店编号,今天的销售额与去年的销售额。来自两个不同的表格。
现在我想添加另一个显示商店名称的表。我怎么能这样做?
商店名称位于名为[Company$Store]
的表格中,字段为#34;名称"。
我希望它加入[Company$Store].No_ = [Company$Trans_ Sales Entry].[Store No_]
这是我要添加它的查询:
Select t.Store, t.Sales, a.[Last year]
From (Select [Company$Trans_ Sales Entry].[Store No_] As Store,
Sum([Company$Trans_ Sales Entry].[Net Amount] * -1) As Sales
From [Company$Trans_ Sales Entry]
Where [Company$Trans_ Sales Entry].Date = Convert(date,GetDate())
And [Company$Trans_ Sales Entry].[Store No_] Not Like '5%'
Group By [Company$Trans_ Sales Entry].[Store No_]
) t
Full Outer Join
(Select [Company$Archived Sales Entry].[Store No_] As Store,
Sum([Company$Archived Sales Entry].[Net Amount] * -1) As [Last year]
From [Company$Archived Sales Entry]
Where [Company$Archived Sales Entry].Date = Convert(date,DateAdd(week, -52, GetDate()))
Group By [Company$Archived Sales Entry].[Store No_]
) a
On a.Store = t.Store
Order By t.Store
希望有人可以提供帮助!
答案 0 :(得分:0)
Select [Company$Trans_ Sales Entry].[Store No_] As Store, [Company$Store].[Name],
Sum([Company$Trans_ Sales Entry].[Net Amount] * -1) As Sales
From [Company$Trans_ Sales Entry]
JOIN [Company$Store]
ON [Company$Store].No_ = [Company$Trans_ Sales Entry].[Store No_]
Where [Company$Trans_ Sales Entry].Date = Convert(date,GetDate())
And [Company$Trans_ Sales Entry].[Store No_] Not Like '5%'
Group By [Company$Trans_ Sales Entry].[Store No_], [Company$Store].[Name]