我想编写一个查询来返回表中的所有记录,
如果特定列value
低于100,则add +5
为值
答案 0 :(得分:1)
每个订单的sum
值都需要。根据您的原始问题orderamount <100
,然后添加5
WITH cte
AS (
SELECT OrderID
,OrderDate
,Customer
,ProductAmount
,sum(orderamount) orderamount
FROM mytable
GROUP BY OrderID
,OrderDate
,Customer
,ProductAmount
)
SELECT OrderID
,OrderDate
,Customer
,ProductAmount
,CASE
WHEN orderamount < 100
THEN orderamount + 5
ELSE orderamount
END Orderamount
FROM cte