SQL select command with addition

Hi there,

I have an SQL table in the following format.  
[ID, NAME, Duration, PhoneNumber, CallType]
1, "abc", 12, 123-4566, INCOMING
2, "abc", 8, 123-4566, OUTGOING
3, "cde", 8, 123-4566, INCOMING
4, "cde", 12, 123-4566, OUTGOING
5, "cde", 10, 123-4566, INCOMING
6, "cde", 12, 123-4566, OUTGOING
7, "abc", 12, 123-4566, OUTGOING
8, "abc", 25, 123-4566, INCOMING
9, "abc", 5, 123-4566, INCOMING
I want to do some arithmetric on the columns and want to get a result in the following format.  Basically, I want to list Total Incoming and Outgoing Duration and the number of calls for each name.

The result should be like this.

[Name, Total Incoming Duration, Number of Incoming Calls, Total outgoing Duration, Number of Outgoing calls]
abc, 42, 3, 20, 2
cde, 18, 2, 24, 2

Can you please let me know what would be the query command for this.  Thank you
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

  , SUM(CASE WHEN CallType='INCOMING' THEN Duration ELSE 0 END) as `Total_Incoming_Duration`
  , SUM(CASE WHEN CallType='INCOMING' THEN 1 ELSE 0 END) as `Number_of_Incoming_Calls`

  , SUM(CASE WHEN CallType='OUTGOING' THEN Duration ELSE 0 END) as `Total_Outgoing_Duration`
  , SUM(CASE WHEN CallType='OUTGOING' THEN 1 ELSE 0 END) as `Number_of_Outgoing_Calls`

FROM Tablename

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.