mysql - ShoreTel MySQL 查询

标签 mysql database shoretel

背景信息:

我的公司使用 ShoreTel 提供 VoIP 服务;虽然他们的预设报告很棒,但他们提供了我们不需要的信息,而且演示文稿也不是最容易使用数据的。我需要针对所有销售电话创建一个报告,最终合并 ShoreTel 提供的两个预设报告 - 个人报告和团体报告;合并这两个报告的原因是为了获得一个数据透视表,销售经理可以查看并快速消化每个销售人员/组的调用。我已经对 MySQL Workbench 中的数据库进行了逆向工程,并找到了应返回我想要的特定数据的所有表和列。下面列出的三个表和列是生成我希望在报告/数据透视表中使用的数据的表和列:

agentactivity                   |   Connect                     |   Call
-------------                       ---------                       ------
agentactivity.StartTimeStamp    |   connect.PartyTable          |   call.CallType
agentactivity.EndTimeStamp      |   connect.ConnectReason       |   call.DialedNumber
agentactivity.AgentDN           |   connect.PartyID             |   call.CallerID
agentactivity.AgentFirstName    |   connect.PartyIDName         |   call.Duration
agentactivity.AgentLastName     |   connect.Duration            |   call.Extension 
agentactivity.State             |   connect.TalkTimeSeconds     |
agentactivity.WorkgroupDN       |                               |
agentactivity.WorkgroupName     |                               |

由于我是使用 MySQL 的新手,所以我需要帮助的是构建一个查询,我可以用它来挖掘我想要的数据;我可以构建单独的查询来获取部分数据(如下所示),但是当涉及到使用两个(更不用说三个)表时,这一切都开始崩溃。我尝试了自己的查询,但我想确保这在语法和可用性方面是正确的。如上所述,这样做的目的是使用数据库中的所有必需信息创建一个数据透视表。

之前阅读/尝试过:

http://stackoverflow.com/questions/14191506/how-to-join-two-tables <-Helped a little but not a lot; still confused.

http://stackoverflow.com/questions/22418525/shoretel-outgoing-calls-query <--Provide more information; was able to build off this one on my own, only able to use for single results.

http://stackoverflow.com/questions/20405898/multiple-select-case-staments-in-query-for-shoretel-reports?rq=1 <--Was not what I needed for my task.

https://community.spiceworks.com/how_to/69423-shoretel-call-detail-record-lookup <--Most helpful yet and I tried customizing this to suit my needs; failed.

https://www.experts-exchange.com/questions/28286779/Shoretel-SQL-query-in-Excel.html <--Was not useful in anyway as I need the correct query to dump data into Excel.

http://dev.mysql.com/doc/refman/5.7/en/join.html <--This is where I started regarding 'Joins' for tables but it starts to get confusing.

我对单个数据返回的查询(说实话,这些最初不是我的查询,我自定义了它们以满足我的需求):

SELECT PartyIDName,GroupID,ConnectTime,DisconnectTime,ConnectReason 
FROM shorewarecdrarchive.`connect` 
WHERE PartyType=12;

SELECT StartTime,DialedNumber,CallerID,EndTime,Extension,CallType 
FROM shorewarecdrarchive.`call` 
WHERE Extension=6333 AND date(StartTime) BETWEEN '2016-08-01' AND '2016-08-16' AND CallType=3;

SELECT ID, StartTime, StartTimeMS, EndTime, EndTimeMS, TIMEDIFF(EndTime,StartTime) AS `CallDuration`, LongDistance, CallType, CallerID, DialedNumber, Extension 
FROM shorewarecdrarchive.`call` 
WHERE Extension=6317 DATE(StartTime) = '2016-09-01' AND TIME(StartTime) >= '00:00:00' AND TIME(StartTime) <= '23:59:59' ORDER BY CallType,StartTime;

我尝试使用多个表进行查询:

SELECT
    call.CallType,
    call.DialedNumber,
    call.CallerID,
    call.Duration,
    connect.PartyTable,
    connect.ConnectReason,
    connect.PartyID,
    connect.PartyIDName,
    connect.PartyIDLastName,
    connect.Duration,
    connect.TalkTimeSeconds,
    agentactivity.StartTimeStamp,
    agentactivity.EndTimeStamp,
    agentactivity.AgentDN,
    agentactivity.AgentFirstName,
    agentactivity.AgentLastName,
    agentactivity.State,
    agentactivity.WorkgroupDN,
    agentactivity.WorkgroupName 
FROM 
    shorewarecdrarchive.`call` 
    INNER JOIN shorewarecdrarchive.`connect` 
        ON connect.CallTableID=call.ID 
    INNER JOIN shorewarecdrarchive.'agentactivity' 
        ON call.Extension=agentactivity.AgentDN 
WHERE 
    TIME(StartTime) >= '00:00:00' 
    AND TIME(StartTime) <= '23:59:59' BETWEEN '2016-09-01' AND '2016-09-16' 
ORDER BY 
    CallType,StartTime;

对此的任何和所有帮助将不胜感激!

最佳答案

感谢mcNet感谢您对我遇到的这个问题的帮助。下面的查询有效,可用于挖掘出 jar 装个人和团体报告中的所有数据。

SELECT 
    call.CallType,
    call.DialedNumber,
    call.CallerID,
    connect.PartyType,
    connect.ConnectReason,
    connect.PartyID,
    connect.PartyIDName,
    connect.PartyIDLastName,
    connect.TalkTimeSeconds,
    agentactivity.StartTimeStamp,
    agentactivity.EndTimeStamp,
    agentactivity.AgentDN,
    agentactivity.AgentFirstName,
    agentactivity.AgentLastName,
    agentactivity.State,
    agentactivity.WorkgroupDN,
    agentactivity.WorkgroupName
FROM
    shorewarecdrarchive.call
LEFT JOIN
    shorewarecdrarchive.connect ON connect.CallTableID = call.ID
LEFT JOIN
    shorewarecdrarchive.agentactivity ON call.Extension = agentactivity.AgentDN
WHERE
    StartTime >= '2016-09-01 00:00:00'
AND StartTime < '2016-09-17 00:00:00';

再次感谢您的帮助。

关于mysql - ShoreTel MySQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40898519/

相关文章:

mysql - 找不到 Curses 库

javascript - 使用 jEditable、jQuery 和 DataTables 更新表中的单元格

mysql - 在SQL select语句中,为什么使用 "1 order by "或 "order by 1"?

java - 使用 nosql(比如 mongodb)会提高开发效率吗?

java - 我应该在 Solr(或任何数据库)中索引或存储这些字段吗?

sql-server - 计算 SQL Server 数据库中字符串的哈希值——值得付出努力吗?

mysql - VB.NET 和 MySQL 查询

mysql - ShoreTel 数据库中的哪个位置处理实时调用?

mysql - SQL Shortel 放弃调用查询