Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting of Rows with the same string occurrencies

Status
Not open for further replies.

estersita

Technical User
Aug 5, 2004
50
US
Hi!

I am trying to count occurrences (rows) which contain equal strings break on the same fileld

In other words I need counting subtotal and total but I do not need computation as these are just strings

For example I have:

Code

Zp
Zp
Zp
Zp
No
No
No
Yes
Yes

What I need is:

Zp
---------------
Subtotal =4

No
__________
Subtotal=3
Yes
__________
Subtotal=2

Could you please help me with it?

Thank you in advance!

Estersita


 
SELECT code, count(*)
FROM my_table
GROUP BY code;
 
Carp,

Thank you for your quick response. I wonder however if it would be correct if I chose to include other filelds in the output.

For ex:

SELECT anotherFld,code, count(*)
FROM my_table
GROUP BY code;

Should I include them into GROUP BY clause?
OR
If I do not...then would it be correct?

Thank you !

Estersita

 
Code:
SELECT anotherFld,code, count(*) 
FROM my_table
GROUP BY code;
won't work since you need to GROUP BY every non-grouping item in your SELECT list. Consequently, you would need to use
Code:
SELECT anotherFld, code, count(*) 
FROM my_table
GROUP BY anotherFld, code;
which may not be what you want.

Please post your full situation so that we can respond to the real problem rather than providing iterative answers that eventually get you to where you want to go. Are you running this via sql*plus, or another reporting tool? How many different fields are you really including? What other types of values are you looking for? The more information you provide in your initial post, the faster you are likely to get a solution that's suitable for your problem.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top