如何查询表以获得通话费用

发布于 2024-10-31 15:50:28 字数 285 浏览 4 评论 0原文

我需要执行什么查询来计算 mysql 数据库中的调用成本?

我有两张表,一张是带有通话时长的通话记录,另一张是带有高峰和非高峰费率的资费表,高峰时间是 08:00:00 - 19:00:00 非高峰时间是 19:00:00 - 08:00:00。高峰时段的费率是每分钟 10 便士或每秒 0.9992 或类似的价格。和非高峰 2 点分钟。

我想知道如何查询这两个表来根据通话时长和通话费用-每秒/分钟的费率来计算通话费用。

输出将在另一个表中,其中包含 CallerId、来源、目的地、通话持续时间、通话费用

What Query would I need to do to calculate cost of calls in mysql database?

Ive got two tables, one is a call log with call duration, and the other table is the tariff table with peak and offpeak rates, peaktime is 08:00:00 - 19:00:00 offpeak time is 19:00:00 - 08:00:00. rates for peak are say 10p a minute or 0.9992 a second or something on the lines of that. and offpeak 2p minute.

I want to know how to query the two tables to calculate the cost of call according to the call duration and the cost of the call - Rate per sec/minute.

Output would be on another table with CallerId, Source, Destination, call duration , cost of call

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那支青花 2024-11-07 15:50:28

这看起来相对简单(这通常意味着我错过了一些东西)。

从假设开始。假设 CALL_LOG 表如下所示:

CallerId
Source
Destination
Duration
CallStartTime
CallStopTime

。 。 。 TARRIFF 表如下所示:

Id
RateType (Peak or OffPeak)
RateStartTime
RateStopTime
Rate

我们假设您正在使用 Oracle,因为我没有看到具体提及。但你说的是 CDR,所以可能有很多记录,所以可能是 Oracle。 (注意:我删除了 Oracle 特定代码,并决定将其作为内部联接来执行。不过可能会太慢,具体取决于数量。)

让我们假设“非高峰呼叫”的定义是在非高峰时间开始的呼叫,无论其何时结束。 (请注意,此定义对于正确执行此操作至关重要。)

最后,根据您的评论,我们假设只有两种费率:高峰和非高峰。这看起来很奇怪,但是没关系。我本以为时间会每天有所不同,以考虑周末费率,但您应该能够推断。

因此,通话费用为

SELECT l.CallerId, 
       l.Source, 
       l.Destination, 
       l.Duration, 
       t.RateType, 
       l.Duration * t.Rate as Cost
FROM CALL_LOG l
  INNER JOIN TARRIF t
    ON l.CallStartTime BETWEEN t.RateStartTime and t.RateStopTime

This seems relatively straight forward (which usually means I am missing something).

Starting with assumptions. Say the CALL_LOG table looks like this:

CallerId
Source
Destination
Duration
CallStartTime
CallStopTime

. . . and the TARRIFF table looks like this:

Id
RateType (Peak or OffPeak)
RateStartTime
RateStopTime
Rate

And let's assume you are using Oracle, since I don't see that specifically mentioned. But you say CDRs, so probably lots of records, so maybe Oracle. (NOTE: I removed the Oracle specific code and decided to do this as an inner join. Might be too slow though, depending on volume.)

And let's assume that the definition of an "off peak call" is a call that starts during an off-peak time, regardless of when it ends. (Note that this definition is critical to doing it correctly.)

Lastly, let's assume that there are only two rates, peak and off-peak, based on your comments. That seems strange, but ok. I would have thought that the times would differ by day, to allow for weekend rates, but you should be able to extrapolate.

So the cost for a call would then be

SELECT l.CallerId, 
       l.Source, 
       l.Destination, 
       l.Duration, 
       t.RateType, 
       l.Duration * t.Rate as Cost
FROM CALL_LOG l
  INNER JOIN TARRIF t
    ON l.CallStartTime BETWEEN t.RateStartTime and t.RateStopTime
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文