Gossamer Forum
Home : General : Databases and SQL :

COUNT() function and scope

Quote Reply
COUNT() function and scope
Hi. I work with kbSQL and I'm having a problem with using count()...

I have to run totals for each type of exam, then the totals of all exams for a given time period that meet some other criteria also... I'm using the count() statement to do this, but when I get to the end and I try to use the count() to give the total of all exams, it just repeats the value of the last row... is there any way I can make the scope for the count() statement global when I do it in my final event?
Quote Reply
Re: [kellogs] COUNT() function and scope In reply to
This in Perl/PHP? Can you post a few bits of sample codes you are using?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] COUNT() function and scope In reply to
no, its in KB Sql, which is sort of a crossup between SQL and M... I don't know much about SQL, as we just got the feature not too long ago and they said "you do programming, do this..." (I'm an intern) But what I do know about it I picked up from the reference they had here and all... but here's the code that I used below...

"acc_primary" is one of the primary keys for the table Exam, and the primary key for the Report data table. I work with a hospital database, and if it matters, Its a VAX running openVMS at the core.

select e.exam_code heading "Exam code", count(e.acc) heading "Total Examinations"

from exam e,report_data r

where (e.comp_date between "09/01/03" and "09/16/03") and

(e.comp_time is not null) and

(e.acc_primary = r.acc_primary) and



((r.lst_sgn_num = 8857) or (r.rad1_int_num = 8857) or


(r.rad2_int_num = 8857) or (r.rad3_int_num = 8857))

order by e.exam_code

group by e.exam_code

final

write "Total Exams: " | count(*)

Quote Reply
Re: [kellogs] COUNT() function and scope In reply to
It would be better using the SUM function rather than COUNT.
========================================
Buh Bye!

Cheers,
Me