想知道下面我的查询有什么问题?
case
b.transaction_id,
when b.total_discount<0 then (ABS(b.total_discount)/(b.total_revenue + ABS(b.total_discount)) else '0' end as pct_discount_off
from transaction b
出现错误消息。
Msg 156, Level 15, State 1, Line 27
Incorrect syntax near the keyword 'end'
答案 0 :(得分:1)
您错过了closing bracket ')'
:
case
b.transaction_id
when b.total_discount<0
then (ABS(b.total_discount)/(b.total_revenue + ABS(b.total_discount)))
else '0' end as pct_discount_off
答案 1 :(得分:0)
我认为你在寻找的是
SELECT case
when b.total_discount < 0 then (ABS(b.total_discount)/(b.total_revenue + ABS(b.total_discount)))
else '0' end as pct_discount_off
from [transaction] b
答案 2 :(得分:0)
使用
select case b.transaction_id when b.total_discount<0 then (ABS(b.total_discount)/(b.total_revenue + ABS(b.total_discount)) else '0' end as pct_discount_off from transaction b