Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Using the count function
Old 12-07-2005, 09:51 AM Using the count function
numbenator's Avatar
Webmaster Talker

Posts: 516
Location: London
Trades: 0
Hi there ,
I have the below script

select
count(*),
b.intbranchid,
h.intCatID
from
tblcontent_hac_cat h inner join tbl_br_branch b on b.intbranchid = h.intbranchid
group by
b.intbranchid,
h.intCatID

order by b.intbranchid

It works however count count(*) isn't counting. next to each record, I get 1 where as I wish the count to increment each time intBranchID the same and reset when changes.



1 1 69
1 1 71
1 3 70
1 3 67
1 7 68
1 8 72
1 9 73
1 10 74
1 11 75

I want the results to be as :

1 1 69
2 1 71
1 3 70
2 3 67
1 7 68
1 8 72
1 9 73
1 10 74
1 11 75

So as I can output the total number of records per column 2

Any input would be appreciated
__________________

Please login or register to view this content. Registration is FREE

Last edited by numbenator; 12-07-2005 at 09:55 AM..
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
 
Register now for full access!
Old 12-07-2005, 03:01 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
You are grouping on two columns, so every group turns out to be unique (ie it counts 1 69 and 1 71 as different groups cos the second ID is different).

Even if you wen to only one column it probably wouldn't work, and instead come out
2 1 71
2 3 67
1 7 68
1 8 72
1 9 73
1 10 74
1 11 75

This is because count(*) is there to tell you how many of some group there are, not how many there have been so far. Depending on how your script handles these results, I would just loop through the results and keep a counter in PHP/ASP, that I reset if the branch id is different to last time.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Reply     « Reply to Using the count function
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24793 seconds with 12 queries