Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Brilliant! Your site is great...and saving me hours of time at work and making my boss think I am brilliant too! I also picked up on a thread that will potentially save us a lot of money in the future..."

Geography

Where in the world do Tek-Tips members come from?
jasonhuibers (Programmer)
10 Nov 11 9:12
Results of query are presently like this:
Category    Count    Status
Books        20    Closed
Books        10    OPEN


I would like to have them on one line like this - where Created_Count= Closed + Open:
Category    Closed_Count    Created_Count
Books        20        30



 SELECT
  B.Category,
count(distinct A.ID) COUNT,
CASE WHEN A.STATUS = 'C' THEN
          'CLOSED'  
  ELSE
          'OPEN'
  END STATUS        
  FROM
                Table1 A ,
                Table2 B
  WHERE  
                B.CATEGORY = A.CATEGORY
            AND B.DES= 'Books'
     AND TRUNC(A.DATETIME_STAMP)    >= to_date('01-01-2011','DD-MM-YYYY')           
group by B.DES,a.STATUS;



 
Dagon (MIS)
14 Nov 11 5:36
What exactly is the problem that you are having?  Also, what are your table definitions?

SantaMufasa (TechnicalUser)
14 Nov 11 16:09
Another issue...The contents of CATEGORY and DES appear to be the same...it that correct?

santaMufasa
(aka Dave of Sandy, Utah, USA)
"People may forget what you say, but they will never forget how you made them feel."

SantaMufasa (TechnicalUser)
14 Nov 11 16:59
Here is a solution for you that uses virtual tables:

CODE

select x.category, Closed_count, Created_Count
  from (select a.category, count(*) closed_count
          from table1 A, table2 B
         where B.CATEGORY = A.CATEGORY
           and B.DES= 'Books'
           and TRUNC(A.DATETIME_STAMP) >= to_date('01-01-2011','DD-MM-YYYY')
           and a.status = 'C'
         group by a.category
               ) x
      ,(select a.category, count(*) created_count
          from table1 A, table2 B
         where B.CATEGORY = A.CATEGORY
           and B.DES= 'Books'
           and TRUNC(A.DATETIME_STAMP) >= to_date('01-01-2011','DD-MM-YYYY')
         group by a.category
               ) y
 where x.category = y.category
 order by 1
/

CATEGORY   CLOSED_COUNT CREATED_COUNT
---------- ------------ -------------
Books                20            30

1 row selected.
Let us know if this solves your need.

santaMufasa
(aka Dave of Sandy, Utah, USA)
"People may forget what you say, but they will never forget how you made them feel."

Helpful Member!  Beilstwh (Programmer)
15 Nov 11 14:56

CODE

SELECT
  B.Category,
sum(decode(a.status,'C',1,0)) closed,
sum(decode(a.status,'C',0,1)) open,
sum(1) created_count
 FROM
                Table1 A ,
                Table2 B
  WHERE  
                B.CATEGORY = A.CATEGORY
            AND B.DES= 'Books'
     AND TRUNC(A.DATETIME_STAMP)    >= to_date('01-01-2011','DD-MM-YYYY')           
group by B.Category;

Bill
Lead Application Developer
New York State, USA

SantaMufasa (TechnicalUser)
15 Nov 11 15:07
Excellent improvement, Bill. I shoulda thunka that myself. Hava !

santaMufasa
(aka Dave of Sandy, Utah, USA)
"People may forget what you say, but they will never forget how you made them feel."

stefanhei (TechnicalUser)
16 Nov 11 6:10
The OP used count(distinct a.id). If the join returns duplicate ids a slightly modified version Santas approach - count(distinct id) instead of count(*) - would produce the desired result.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close