SQL Math Question
#1
SQL Math Question
Is it possible to add two figures up that are in the same column as each other?
For instance;
select department, count(*)
from table
where deparment in ('55', '60')
group by department
I now have two rows returned one with a count of how many rows are in department 55 another with a count of how many rows are in department 60.
How do i now add those two figures together?
Any help would be great.
Cheers
For instance;
select department, count(*)
from table
where deparment in ('55', '60')
group by department
I now have two rows returned one with a count of how many rows are in department 55 another with a count of how many rows are in department 60.
How do i now add those two figures together?
Any help would be great.
Cheers
#5
Scooby Regular
Join Date: Sep 2001
Location: A powerslide near you
Posts: 10,261
Likes: 0
Received 0 Likes
on
0 Posts
SELECT
COUNT(CASE WHEN department = '55' THEN 1 ELSE 0),
COUNT(CASE WHEN department = '60' THEN 1 ELSE 0),
COUNT(CASE WHEN department = '55' THEN 1 ELSE 0) - COUNT(CASE WHEN department = '60' THEN 1 ELSE 0),
COUNT(CASE WHEN department = '60' THEN 1 ELSE 0) - COUNT(CASE WHEN department = '55' THEN 1 ELSE 0)
FROM table
Gives you count of 55, count of 60, count of 55s - 60s and count of 60s - 55s
COUNT(CASE WHEN department = '55' THEN 1 ELSE 0),
COUNT(CASE WHEN department = '60' THEN 1 ELSE 0),
COUNT(CASE WHEN department = '55' THEN 1 ELSE 0) - COUNT(CASE WHEN department = '60' THEN 1 ELSE 0),
COUNT(CASE WHEN department = '60' THEN 1 ELSE 0) - COUNT(CASE WHEN department = '55' THEN 1 ELSE 0)
FROM table
Gives you count of 55, count of 60, count of 55s - 60s and count of 60s - 55s
Thread
Thread Starter
Forum
Replies
Last Post
Brzoza
Engine Management and ECU Remapping
1
02 October 2015 05:26 PM