SQLite multiple SUM(*) functions

Using SQLite can I get multiple SUM statements into a single results table?
For example I would like to combine the two statements below into a single statement

SELECT
      SUM("Total Cut Length") AS instro
FROM
      cableList
WHERE
      "Service" = "Instrument";

SELECT
      sum("Total Cut Length") AS elec
FROM
      cableList
WHERE
      "Service" = "Electrical";
Sam KAsked:
Who is Participating?

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

x
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.

Arun MuruganCommented:
Try this.
SELECT
   SUM(CASE
          WHEN Service = "Instrument"
             THEN 1
          ELSE O
       END) AS instro,
   SUM(CASE
          WHEN Service = "Electrical"
             THEN 1
          ELSE O
       END) AS elec
FROM
   cableList
WHERE
   Service IN ("Instrument","Electrical");

Open in new window

Sam KAuthor Commented:
Thank you Arun, that counts the number of instances of the two values, however i am trying to get the sum of the values.
Lets say I have two electrical cables each with a length of 100 and five instro cables each with a length of 20
i am trying to get the results table to display the sum of electrical = 200 and the sum of instro as 100
Arun MuruganCommented:
Got you. Place the length-column-name in "col_length" in the below query.
SELECT
   SUM(CASE
          WHEN Service = "Instrument"
             THEN col_length
          ELSE 0
       END) AS instro,
   SUM(CASE
          WHEN Service = "Electrical"
             THEN col_length
          ELSE 0
       END) AS elec
FROM
   cableList
WHERE
   Service IN ("Instrument","Electrical");

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
Sam KAuthor Commented:
That got it :) Thank you
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
Query Syntax

From novice to tech pro — start learning today.