1

我希望我制定 ddl +dml 查询和我的问题没有错误。

我建立这个查询

DECLARE @temp TEHOODOTRECHESH
(
      VendorCode INT
    , VendorName NVARCHAR(50)
    , CheckDate DATETIME
    , CheckSum DECIMAL(10,2)
    , ObjType INT
)

INSERT INTO @temp TEHOODOTRECHESH (VendorCode, VendorName, CheckDate, CheckSum,ObjType
VALUES 
    (1, 'AAA', '20130101', 40,18),
    (1, 'AAA', '20130101', 60,18),
    (1, 'AAA', '20130101', 40,19),
    (2, 'BBB', '20130303', 50,18),
    (2, 'BBB', '20130601', 10,18),
    (2, 'BBB', '20130604', 20,19)


SELECT * FROM 
( SELECT 
case when [ObjType]='18' then N'tr' else N'tz' end as 'DT',  
CARDCODE, 
CardName,
year(DocDueDate) as 'year',left(datename(month,DocDueDate),3) as [month], 
DocTotal as 'Amount'
FROM TEHOODORRECHESH
WHERE DocStatus ='O' ) as monthsum
PIVOT 
(
sum (Amount)
for [month] IN (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, 
nov, dec) ) AS SUMPIVOT

  1. 我想对来自 ObjType 18 / 19(只有两种类型)的文档行求和,并按月对 objtype 求和。
  2. 是否有机会如果 ObjType 19 将数字减去操作符 (-) 或将在括号中 ()
  3. 当我仅按供应商代码编写订单时,它可以工作,但如果我添加订单:vendorcode + objtype 它不起作用。为什么?
4

0 回答 0