我有月表MONTHNAME,MonthNumber和整个财年7月份开始,所以我已经分配的值的几个月就像SQL查询外与集团参加由
MONTHNAME =七月和MonthNumber = 1
MonthName = August和MonthNumber = 2。 MonthName = August和MonthNumber = 2。
我有另一个域表BudgetCategory它有BudgetCategoryId,BudgetCategoryName。
PurchaseOrder表中有OrderID,PurchaseMonth,BudgetCategoryId。
现在我想查询找出每个BudgetCategory每月购买SUM(TOTALCOST)。如果没有购买任何BudgetCategoryId我想在报告中显示零。表
模式:
CREATE TABLE [dbo].[BudgetCategory](
[BudgetCategoryId] [numeric](18, 0) NOT NULL,
[BudgetCategoryName] [varchar](50) NULL,
[TotalBudget] [nvarchar](50) NULL)
CREATE TABLE [dbo].[PurchaseOrder](
[OrderId] [bigint] NOT NULL,
[BudgetCategoryId] [bigint] NULL,
[PurchaseMonth] [nvarchar](50) NULL,
[QTY] [bigint] NULL,
[CostPerItem] [decimal](10, 2) NULL,
[TotalCost] [decimal](10, 2) NULL)
CREATE TABLE [dbo].[MonthTable](
[MonthNumber] [bigint] NULL,
[MonthName] [nvarchar](30) NULL)
每月购买 - 你想知道的总和,计数,真/假呢? – user2989845
我想知道每月每个BudgetCategory的SUM(TotalCost)... –
如何将采购订单与月份相关联? –