Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Posts
    3

    Post Unanswered: SQL query results - help please

    Hi,

    Is there a way in SQL to display the same column with different conditions in one row? For example, if I have EMP table as follows:

    emp_id | status | tier
    ********************
    111111 | Active | 1
    222222 | Active | 1
    333333 | Cancel| 1
    444444 | Cancel| 2

    Then I need a query, which result is:

    tier | number of active emp | number of cancelled emp
    *********************************************
    1 | 2 | 1
    2 | 0 | 1

    Thanks!!!

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    PHP Code:
    SELECT   tier
             
    SUM (DECODE (status'Active'10)) active,
             
    SUM (DECODE (status'Cancel'10)) cancelled
        FROM emp
    GROUP BY tier


  3. #3
    Join Date
    Feb 2004
    Posts
    3

    Thumbs up

    Great, thanks a million!

  4. #4
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    You're welcome

Posting Permissions

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