【发布时间】:2019-11-08 18:04:58
【问题描述】:
我有 2 个表 = 客户及其通话记录
现在我想根据通话时长以及特定月份(比如 2015 年 1 月)向他们收费。
这是计算通话费用的标准 -
A) 对于来电,收费为每秒 1 个单位。 Example if the duration is 250 seconds then cost is 250
B) 对于拨出电话,for the first 2mins, the cost is fixed at 500 units。随后几秒钟的费用为2 units per second。
例如,如果传出持续时间为 5 分钟,则费用为 500 units + 2*3*60 units = 860 units
下表是:
customer table with columns id, name, phone
history table with columns id, incoming_phone, outgoing_phone, duration, dialed_on (YYYY-MM-DD)
我针对我的情况提出了以下查询:
来电费用:
select c.name, c.phone, h.duration as cost
from customer c join history h on c.phone = h.incoming_phone
当我运行上述查询时,我没有收到任何语法错误。
拨出电话费用:
select c.name, c.phone, CASE
WHEN h.duration > 120 THEN 500 + 2*(h.duration-120)
ELSE 2*(h.duration-120)
END; as cost
from customer c join history h on c.phone = h.outgoing_phone
当我运行上述查询时,我得到了syntax error like "ERROR 1109 (42S02) at line 1: Unknown table 'c' in field list"
我想加入这两个查询并获取总费用并将字段显示为姓名、电话、费用
我仍然需要为特定月份添加一个条件来限制 2015 年 1 月的数据,但我被这个方法卡住了。
【问题讨论】: