Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Query Help for Newbie

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-14-04, 07:47
Rich Petersen Rich Petersen is offline
Registered User
 
Join Date: Jun 2004
Posts: 3
Query Help for Newbie

Hello all,

I have two tables (among others) that track the amount of documents scanned in a batch for a scanning application.

The table StatsBatch will have one record for each batch of documents, and there is an associated record in the table StatsBatchModule that tracks number of documents, pages, etc..

When a person scans, they select what Batchclass they want to use, lets call it BatchClassA, BatchClassB, BatchClassC.

I want to total the number of batches, then total the documents, and pages for each Batchclass, not individual batches. So if I scan 3 batches of BatchClassA, and the first one as 2 docs of a total of 5 pages, the second one has 4 docs with a total of 7 pages, and the third has 17 docs, with 1000 pages, then the return should show:

BatchClassA 3 23 1012

BatchClassA(name of batch) 3 (number of batches), 23 (number of total docs) and finally 1012 (number of pages).

Here is what I have so far:

Select distinct A.BatchClass, count(A.batchclass) as Batches, sum(B.DocumentsCreated) as Document, sum(B.PagesScanned) as Pages
From StatsBatch A, StatsBatchModule B
where A.externalbatchid = B.externalbatchid
Group by A.BatchClass
Order by A.BatchClass Asc

Everything works fine, except I am getting an invalid number of batches per batchclass. I figure the "Count(A.BatchClass) is not right, but I am not sure how to reconfigure the query to get the accurate count of how many of each batchclass there is.

Any help would be appreciated.

Thanks,
Rich
__________________
Thanks, and have a great day.....
Rich
Reply With Quote
  #2 (permalink)  
Old 06-14-04, 08:45
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,555
Code:
select A.BatchClass , count(distinct A.externalbatchid) as Batches , sum(B.DocumentsCreated) as Document , sum(B.PagesScanned) as Pages from StatsBatch A inner join StatsBatchModule B on A.externalbatchid = B.externalbatchid group by A.BatchClass order by A.BatchClass asc
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #3 (permalink)  
Old 06-14-04, 08:58
Rich Petersen Rich Petersen is offline
Registered User
 
Join Date: Jun 2004
Posts: 3
Thanks a lot to you both, that did it.

Really appreciate it...
__________________
Thanks, and have a great day.....
Rich
Reply With Quote
  #4 (permalink)  
Old 06-14-04, 09:03
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,555
both? heh

the other guy apparently took a hike and deleted his posts
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #5 (permalink)  
Old 06-14-04, 09:46
derrickleggett derrickleggett is offline
Registered User
 
Join Date: Apr 2004
Location: Kansas City, MO
Posts: 734
You're so good, he thought you were two people.
__________________
MeanOldDBA
derrickleggett@hotmail.com
When life gives you a lemon, fire the DBA.
Reply With Quote
  #6 (permalink)  
Old 06-15-04, 09:47
Rich Petersen Rich Petersen is offline
Registered User
 
Join Date: Jun 2004
Posts: 3
Opps....lol....counted my own post....
__________________
Thanks, and have a great day.....
Rich
Reply With Quote
  #7 (permalink)  
Old 06-15-04, 10:07
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,555
no, rich, you didn't

there were two other posts by some other guy in this thread, but he turned around and deleted them when he saw mine
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
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

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