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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Count Query Help

Status
Not open for further replies.

ncotton

IS-IT--Management
Jan 27, 2006
2,841
GB
I have a list of events.
i.e

A | B
-----
1 | X
2 | Y
3 | X
4 | Z
5 | Z
6 | Z

I need a to structure a query so that I can see the nth most accurance in the B column.

So 2nd most occuring letter in B.

Any help?

Hope this Helps.

Neil J Cotton
njc Information Systems
Systems Consultant
 
Hi Neil!

I'd use this as a temp thing:
Code:
create table occurances nologging as
select
a, 
b,        
row_number() over (partition by B order by A) as OCC
from Neil_Table

Then the OCC column should show you what you need.

Let me know if this isn't what you mean!



Fee

The question should be [red]Is it worth trying to do?[/red] not [blue] Can it be done?[/blue]
 
Fee, can I email you at your WB.com email?

Hope this Helps.

Neil J Cotton
njc Information Systems
Systems Consultant
 
Of course.

Or use the same email address on MSN if that helps.

Fee

The question should be [red]Is it worth trying to do?[/red] not [blue] Can it be done?[/blue]
 
select thing, thang, rank from
(
select thing, thang, rank() over (order by thang desc) as rank
from
(
select thing, count(thing) as THANG
from neil
group by thing
))
where rank = 2


Fee

The question should be [red]Is it worth trying to do?[/red] not [blue] Can it be done?[/blue]
 
Neil - after realising that this will give you odd results if you have tied scores, I suggest the following:

Code:
select thing, thang, rank from
(
select thing, thang, dense_rank() over (order by thang desc) as rank
from
(
select thing, count(thing) as THANG
from neil
group by thing
))
where rank = 2

Hopefully that will work for you.


Fee

The question should be [red]Is it worth trying to do?[/red] not [blue] Can it be done?[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top