将符号添加到sql sum输出

时间:2014-11-04 04:45:17

标签: sql casting sum

我试图在我的总和输出的开头附加'$'。现在我的输出是25.00,0.00等形式,我希望它是,25.00美元,0.00美元等等。我意识到我需要做一些演员,但我尝试的所有变化都会导致错误。

select customer.customer_num, customer.fname, customer.lname, customer.city, 
    customer.state, coalesce(sum(items.total_price),0) amountSpent
from customer
    left join orders
        on customer.customer_num = orders.customer_num
    left join items
        on orders.order_num = items.order_num
        and items.manu_code like 'HRO'
group by customer.customer_num, customer.fname

1 个答案:

答案 0 :(得分:1)

您可以将值转换为varchar

(case when sum(items.total_price) >0 
      then concat('$', cast(sum(items.total_price) as char(100)) ) 
      else '$0' end ) amountSpent