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 > selecting from a query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-19-04, 17:34
fullymooned fullymooned is offline
Registered User
 
Join Date: Apr 2004
Location: ny, ny
Posts: 224
selecting from a query

I generate a query which contains the following
date, workorder, downtime, mttr, deptgroup, status

I need to display the following variables in a report
Could someone help me with the syntax

mach_dt = sum(downtime) where deptgroup = 1
mach_wo = count(workorder) where deptgroup = 1 and status = 1 or 2
pna_dt = sum(downtime) where deptgroup = 2

thank you
Reply With Quote
  #2 (permalink)  
Old 08-20-04, 00:33
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
When you count the workorders, if workorder X appears 5 times do you want it counted once, or all 5 times it appears? What database engine (DB2, MS-SQL, MySQL, Oracle, etc) are you using?

-PatP
Reply With Quote
  #3 (permalink)  
Old 08-20-04, 09:42
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
select 'mach_dt'     as total_type
     , sum(downtime) as total_amount
  from yourquery
 where deptgroup = 1
union all
select 'mach_wo'    
     , count(workorder) 
  from yourquery
 where deptgroup = 1 
   and status in (1,2))
union all
select 'pna_dt'
     , sum(downtime) 
  from yourquery
 where deptgroup = 2
__________________
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