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 > Query Help for Newbie

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-14-04, 06: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
Reply With Quote
  #2 (permalink)  
Old 06-14-04, 07:45
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
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
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 06-14-04, 07: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...
Reply With Quote
  #4 (permalink)  
Old 06-14-04, 08:03
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
both? heh

the other guy apparently took a hike and deleted his posts
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 06-14-04, 08: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, 08:47
Rich Petersen Rich Petersen is offline
Registered User
 
Join Date: Jun 2004
Posts: 3
Opps....lol....counted my own post....
Reply With Quote
  #7 (permalink)  
Old 06-15-04, 09:07
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
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
please visit Simply SQL and buy my book
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