Posted on 2006-04-30
Last Modified: 2009-12-16
Hello experts,

I have a SQL 2K table similar to the following

BallotId      EnteredBy       Vote1          Vote2        Vote3
1              User1              191             312           415
2              User2              193             315           412
3              User3              191             312           455
4              User4              191             333           412
5              User5              193             312           415
6              User6              189             311           455
7              User7              191             312           455
8              User8              193             322           415

The numbers in my example mean nothing other than for illustration purpose.

What I need to determine is the number of times each number appears in a field and order them by the count from that field. Basically I need to know for column Vote1, Vote2, etc.

So my return would look like:
Count   Vote1
4          191
3          193
1          189

I am return this to an asp page and I want them seperately. What I am doing is conducting an online vote of women's fastpitch and they will vote on Coach of the Year, Pitcher of the Year, etc and I need to count the votes and return the information to the user.

Hope this makes sense.

Question by:rcmb
    LVL 75

    Accepted Solution

    Select Count(*) [Count], Vote1
    From YourTableName
    Group By Vote1
    Order By 1 DESC
    LVL 12

    Author Comment

    Thanks for the quick response. Works like a charm.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now