query difference

SELECT COUNT(POPULATION) from CITY
WHERE District= "California";

what is difference between above and below query?

SELECT SUM(POPULATION)
FROM CITY
WHERE DISTRICT = "California";

Please advise
LVL 7
gudii9Asked:
Who is Participating?
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.

slightwv (䄆 Netminder) Commented:
One counts the number of rows.  One adds up all the values.
Mark GeerlingsDatabase AdministratorCommented:
A "count" query will usually return a value much lower than a "sum" query.
Scott PletcherSenior DBACommented:
If population is:
10
20
30
40

COUNT will return 4 (because there are 4 values),
SUM will return 100 (because 10+20+30+40 = 100)
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Geert GOracle dbaCommented:
count population ...
the database is not going to count the people, it's counting the rows in the database

it would be nice if the database could send out some minions to actually go count the people
but that's still fiction
pcelbaCommented:
In words which are understandable by human:
COUNT(POPULATION)  returns the number of cities where the population is known in District California
SUM(POPULATION)  returns the total population of all cities where the population is known in District California
(known = value different from NULL)

More technical summary:
If the data in your database are correct and if they are related to USA then COUNT() should return 0 and SUM() should return NULL because there is no District named California in USA.
gudii9Author Commented:
If population is:
10
20
30
40

in above
COUNT(POPULATION)  returns the number of cities where the population is known in District California
SUM(POPULATION)  returns the total population of all cities where the population is known in District California

10 is number of city1?
20 is number of city2?

i am not clear on this
Please advise
slightwv (䄆 Netminder) Commented:
>>i am not clear on this

Count does just that:  Counts objects starting at 1 and increment by one for every value returned.  The number the value contains doesn't matter.
https://en.wikipedia.org/wiki/Counting

Sum adds up the values returned in the column.
https://en.wikipedia.org/wiki/Summation

So in the example above:  4 values are returned so the COUNT is 4.

Adding (SUM) up all the rows returned returns 100.

10+20+30+40=100
slightwv (䄆 Netminder) Commented:
Set up a quick test and see it in action:
drop table tab1 purge;
create table tab1(col1 number);
insert into tab1 values(12345);
insert into tab1 values(54321);
commit;

select count(col1), sum(col1) from tab1;

COUNT(COL1)  SUM(COL1)
----------- ----------
          2      66666

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
Query Syntax

From novice to tech pro — start learning today.