Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004
    Location
    ny, ny
    Posts
    224

    Unanswered: 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

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •