We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

SQLQuerryforCounts.

sam15
sam15 asked
on
Medium Priority
357 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.
Comment
Watch Question

Sean StuberDatabase Developer & Administrator
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2012

Commented:
I'm not sure what you're looking for, please provide sample data and expected output
awking00Information Technology Specialist
CERTIFIED EXPERT

Commented:
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?

Author

Commented:
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.
Database Developer & Administrator
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2012
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
yes that should do it

replace the value of B1 with A1 and do a DISTINCT COUNT.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.