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

Query to show most frequently appeared number

Status
Not open for further replies.

new2unix

Programmer
Feb 5, 2001
143
US
Hi,

Need help in creating a query showing numbers appearing most frequently under each column, for example:

DATE COLUMN1 COLUMN2
1/1/2004 2 5
1/2/2004 3 2
1/3/2004 4 3
1/4/2004 2 1
1/5/2004 2 5
1/6/2004 3 4

The report would show:

COLUMN1 COLUMN2
2 5

Thanks,

Mike
 
Hi new2unix,

Try this ..

[blue][tt]SELECT TOP 1 COLUMN1,
COLUMN2

FROM YourTable

GROUP BY COLUMN1,
COLUMN2

ORDER BY COUNT(*) DESC;[/tt][/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Thanks, Tony. Based on your example, I found the following portion worked for me:

SELECT TOP 1 COLUMN1, COLUMN2
FROM YourTable;


Mike

 
Hi Mike,

Your change simply finds the first record in whatever order they come. In this example it happens to be the one you want but with different data it probably won't be.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
What if two numbers appear with the same frequency in a column? Do you want to see both numbers or does it matter?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top