If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > count 2 value in a table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-04-04, 15:05
silverxc silverxc is offline
Registered User
 
Join Date: Dec 2004
Posts: 11
Exclamation count 2 value in a table

hi all pls kindly help
need to know how to do a count for 2 value in a column

example :
my table(entries)
has the field name 'selection'
under this selection, data inside have is e.g(apple,apple,pear,pear,pear,orange)
i need to do a COUNT on how many apple and pear there is inside this table

but i seriously have no idea, pls kindly help thanks
Reply With Quote
  #2 (permalink)  
Old 12-04-04, 16:32
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
This sounds like homework from an "Introduction to databases" course, but I'm willing to give you the benefit of the doubt...
Code:
SELECT Count(*), selection
   FROM entries
   GROUP BY selection
   ORDER BY Count(*) DESC -- gratis
-PatP
Reply With Quote
  #3 (permalink)  
Old 12-04-04, 22:28
silverxc silverxc is offline
Registered User
 
Join Date: Dec 2004
Posts: 11
thanks for replying

SELECT Count(*), selection
FROM entries
GROUP BY selection
ORDER BY Count(*) DESC -- gratis


sorry for my ignorance..
wat u meant by DESC over here??

wat i want is to count how many pears and apple there is in that table but not orange
Reply With Quote
  #4 (permalink)  
Old 12-04-04, 22:31
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
DESC means descending, and you don't have to use it if you don't want to

did you want the total of apples and pears? that's different --

SELECT count(*) as applesandpears
FROM entries
WHERE selection in ('apple','pear')
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 12-04-04, 23:23
silverxc silverxc is offline
Registered User
 
Join Date: Dec 2004
Posts: 11
thanks so much....
really so basic

need to read up my books again
Reply With Quote
  #6 (permalink)  
Old 12-04-04, 23:41
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Sorry, my background is showing

Gratis is a Latin vulgate term that means "free of charge" or "complimentary". When I used it in a comment, I meant that I expected it to make things easier to use, without actually impacting the solution at all.

As Rudy pointed out, in this case it simply orders the result set so that the most frequently occuring items appear at the top of the list. You can safely ignore it if it doesn't help you.

-PatP
Reply With Quote
  #7 (permalink)  
Old 12-05-04, 00:23
silverxc silverxc is offline
Registered User
 
Join Date: Dec 2004
Posts: 11
ok got it ..
but still appreciated
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On