Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5995835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:01:04+00:00 2026-05-23T00:01:04+00:00

The call log has the following columns: CallingParty, CalledParty, Duration, EventTime and the example

  • 0

The call log has the following columns:

CallingParty, CalledParty, Duration, EventTime

and the example data is the following:

X, a, 10, 10:20
X, b, 12, 10:34
X, c, 8, 12:08
a, X, 22, 12:45
X, a, 10, 13:55
d, X, 30, 15:01

What I would like to do is to calculate the statistics for each contact (how many times did the user X call the contact, what was the sum of outgoing calls duration, how many times did the contact call user X, and what was the sum of incoming calls duration). Actually I am trying to mine the data from the call log of user X.

The statistics for the example above would be the following:

contactName, incomingCallsCount, IncomingCallsDuration, OutgoingCallsCount, OutgoingCallsDuration
a, 1, 10, 2, 20
b, 0, 0, 1, 12
c, 0, 0, 1, 8
d, 1, 30, 0, 0

I tryed the following query with different joins () but couldn’t fet the right result

    SELECT t1.CallingParty AS Contact, t1.CallingPartyCount, t1.CallingPartyDuration, t2.CalledPartyCount, t2.CalledPartyDuration FROM
(SELECT e.CallingParty, COUNT(*) AS CallingPartyCount, SUM(CAST(REPLACE(e.Duration, 'NULL', '0') AS int)) AS CallingPartyDuration FROM Events e WHERE Duration <> 'NULL' GROUP BY e.CallingParty) t1
<JOIN>
(SELECT e.CalledParty, COUNT(*) AS CalledPartyCount, SUM(CAST(REPLACE(e.Duration, 'NULL', '0') AS int)) AS CalledPartyDuration FROM Events e WHERE Duration <> 'NULL' GROUP BY e.calledParty) t2
ON t1.CallingParty = t2.CalledParty

Does anyone know what would be the right query in order to get the correct statistics?

Thank You!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:01:05+00:00Added an answer on May 23, 2026 at 12:01 am

    You shouldn’t be joining to begin with, it sounds more like a simple group by with sum and count.

    SELECT CallingParty, CalledParty, SUM(Duration), COUNT(*)
    FROM table
    GROUP BY CallingParty, CalledParty
    

    Now, you also need a set of all the users involved (a,b,c and d), that can be computed by using a UNION if you don’t have this somewhere else.

    SELECT CallingParty FROM table
    UNION
    SELECT CalledParty FROM table
    

    Then you just put these together using CTEs.

    WITH outgoing AS (
        SELECT CallingParty, CalledParty, SUM(Duration), COUNT(*)
        FROM table
        GROUP BY CallingParty, CalledParty
    ), incoming AS (
        SELECT CalledParty, CallingParty, SUM(Duration), COUNT(*)
        FROM table
        GROUP BY CalledParty, CallingParty
    ), users AS (
       SELECT CallingParty AS UserID FROM table
       UNION
       SELECT CalledParty AS UserID FROM table
    )
    SELECT * 
    FROM users
    LEFT OUTER JOIN outgoing ON outgoing.CallingParty = UserID
    LEFT OUTER JOIN incoming ON incoming.CalledParty = UserID
    

    That’s should do it!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building application that required some data from iPhone's Call log(read only). The
I'd like to log the number of active threads created by a newCachedThreadPool call.
I'm getting the following exception when I try to call var log = LogManager.GetLogger(this.GetType());
We have a lot of class code which has some boilerplate like the following:
We're looking for a way to log any call to stored procedures in Oracle,
$(item).droppable({ drop: function(event, ui) { console.log(triggered); } }); I try to call drop by
I call the following function with a mouseover event but it's not working. My
A call to clear on a QByteArray generates the following exception: * glibc detected
We have a scenario in which we like to detect when the user has
I have following query in PostgreSQL: SELECT COUNT(a.log_id) AS overall_count FROM Log as a,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.