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 > SQL query results - help please

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-18-04, 03:51
avital avital is offline
Registered User
 
Join Date: Feb 2004
Posts: 3
Post 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!!!
Reply With Quote
  #2 (permalink)  
Old 02-18-04, 06:07
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
PHP Code:
SELECT   tier
         
SUM (DECODE (status'Active'10)) active,
         
SUM (DECODE (status'Cancel'10)) cancelled
    FROM emp
GROUP BY tier

Reply With Quote
  #3 (permalink)  
Old 02-18-04, 08:26
avital avital is offline
Registered User
 
Join Date: Feb 2004
Posts: 3
Thumbs up

Great, thanks a million!
Reply With Quote
  #4 (permalink)  
Old 02-18-04, 08:30
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
You're welcome
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