你可以使用case .. when
语句和解析函数,如下所示:
select Year, Month , customer, Category, Amount,
Case when category = 'Brand'
then
Case when total_sales > 15000 then '2%'
When total_sales > 20000 then '3%'
End
End as disc,
Case when category = 'Brand'
then
Case when total_sales > 15000 then 2*amount/100
When total_sales > 20000 then 3*amount/100
End
End disc_amount
From
(select Year, Month , customer, Category, Amount,
sum(case when category in ('Brand', 'Generic') then amount else 0 end)
over (partition by year, month, customer) as total_sales
from claim)
完美,正是我想要的,感谢您的帮助,也感谢您的评论。你是对的,第二个客户没有折扣