[英]What's wrong with my SQL Case Query
想知道下面我的查询出了什么问题吗?
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'
您缺少右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
我想你要找的是这个
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
采用
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.