Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   sql help
sugster_84
CZ Newbie
sugster_84 has been a member for over 20 year's 20 Year Member
Status: Offline
Joined: Jul 19, 2004
0.00 posts per day
Posts: 5
Points: 308
   
is it possible to count how many times some data appears in my sql database.

for example:-

name age address
natalie 17 magni road
jasper 18 rainbow drive
karen 17 park square
keith 17 riverside park

i am wondering if i could do a count on the age,
17 shows up 3 times.

also could you do this with member id

for example

member id member name age address referral
1 natalie 17 magni road 2
2 jasper 18 rainbow drive 1
3 karen 17 park square 2
4 keith 17 riverside park 2

.....when some one if referred the member id is automactically filled in on the form and goes to the database. i am wondering is it possible in the account area put some code in to tell the member how many referrals they have had..basically do a count on the referral and displaying it in their account. sorry if this doesnt make sense i am finding it hard my self to understand



Back to top Reply with quote
#2   re: sql help
ringo380
CZ Newbie
ringo380 has been a member for over 20 year's 20 Year Member
Status: Offline
Joined: Jul 21, 2004
0.00 posts per day
Posts: 2
Points: 154
   
I'm a total newb at this stuff, but I believe you can just do a "SELECT" statement. For example (taken from the mySQL online manual):

mysql> SELECT t1.name, t2.salary FROM employee t1, info t2 WHERE t1.name = t2.name;


So in your case, I believe it would be something like:

SELECT name, age, address FROM tablename WHERE age = "17"


I've just started learning all this, so I can't guarantee anything, but try it out and see if it works. Let me know if it does so I can add to my ego-points.


Back to top Reply with quote
#3   
aUsTiN
CZ Active Member
usa.gif georgia.gif
Age: 41
Gender: Male
Website:
Status: Offline
Joined: Sep 09, 2003
0.02 posts per day
Posts: 142
Points: 57
  MSN Messenger 
The first one

SELECT COUNT(age) AS total FROM table_name WHERE age = '17';

That would return the amount of times the number 17 is used in the age field.

The second one, i would need a better explanation.



Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum