Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SQLQuerryforCounts.

Posted on 2011-04-19
5
Medium Priority
?
339 Views
Last Modified: 2012-05-11
I have table T1 with a production stages .


T1
----
PR_STAGE


The values allowed are (A1, B1, C1, D1, E1).


I have a query that counts the records based on those stages.

However, A1 and B1 are for same Title.


Is it possible to count either one of those or boths as one record

So if if i have A1 it will be counted 1
if i have B1 it will be counted 1
if i have both A1 and B1 they will be coutned 1.



would you create a derived column and sum on that.
0
Comment
Question by:sam15
  • 2
  • 2
5 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 35426559
I'm not sure what you're looking for, please provide sample data and expected output
0
 
LVL 32

Expert Comment

by:awking00
ID: 35427082
Are you saying that, in addition to the pr_stage column, there is also a Title column and, if a given title has pr_stage of only A1, it should be counted as 1, or has a value of only B1, it should be counted as 1, and if it has both an A1 and B1 values, it should still only be counted as 1?
0
 

Author Comment

by:sam15
ID: 35427975
yes, there is another column. I am just trying to explain it in simple terms.

create table t1 (
pr_stage varchar2(2)
);

insert into t1 values ('A1')
/
insert into t1 values ('B1')
/
insert into t1 values ('C1')
/
insert into t1 values ('D1')
/

Select count(*) from t1 ---> should be 3 beause A1 and B1 point to same titlle.
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 35428623
what if A1 exists twice?  or D1?


if you want a distinct count try...

Select count(distinct decode(pr_stage,'B1','A1',pr_stage)) from t1
0
 

Author Comment

by:sam15
ID: 35429181
yes that should do it

replace the value of B1 with A1 and do a DISTINCT COUNT.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question