【发布时间】:2015-11-02 22:12:19
【问题描述】:
我有一个 MySQL 表,它在用户使用凭单付款时记录数据库中的值。它记录凭证价值。我需要得到按代金券金额细分的所有代金券价值的总和。我目前的查询如下。但是 butchery_class_voucher_155 和 butchery_class_voucher_135 总是返回为 0。
请帮忙解决这个问题。
select
case
when voucher_value = '155.00'
then round(sum(voucher_value/1.2), 2)
else 0.00 end
as butchery_class_voucher_155,
case
when voucher_value = '10.00'
then round(sum(voucher_value/1.2), 2)
else 0.00 end
as shop_voucher,
case when voucher_value = '135.00'
then round(sum(voucher_value/1.2), 2)
else 0.00 end
as butchery_class_voucher_135,
ifnull(round(sum(final_price/1.2), 2),0.00) as paidbycard,
ifnull(round(sum(transfer_fee/1.2), 2),0.00) as transfer_fee
from `bookings`
where `location_id` = 6
【问题讨论】:
-
voucher_value是文本字段吗? -
不,是小数
decimal(9,2) -
那你为什么要做文本比较?
-
@SunKnight0 - 即使我使用 ` = 155` 我仍然得到 0.00 作为结果。
-
@SunKnight0: 没关系,因为 MySQL 会进行隐式转换