Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

SQL Row Counting

  • 17-09-2009 4:37pm
    #1
    Closed Accounts Posts: 448 ✭✭


    My head is fried and I can't seem to think of a way to achieve the following in a single query.

    I have the following tableA

    | id | value |
    | 1 | A |
    | 2 | A |
    | 3 | B |
    | 4 | A |
    | 5 | B |
    | 6 | A |
    | 7 | B |

    How can I use SQL count to return:
    A: 4
    B: 3

    Where the number is the frequency of occurance for a particular value. I have been looking at the count function and examples thereof, and my head keeps saying "Blah!".

    Appreciate any pointers you can offer.


Comments

  • Registered Users, Registered Users 2 Posts: 515 ✭✭✭NeverSayDie


    This should get you in the right direction;
    http://www.w3schools.com/sql/sql_groupby.asp


  • Closed Accounts Posts: 448 ✭✭ve


    /slaps own head :rolleyes:

    Group By, but of course...
    select count(value) from TableA group by value
    

    Oh my head is not working today.

    Cheers ;)


  • Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭Tom Dunne


    ve wrote: »
    /slaps own head :rolleyes:

    Group By, but of course...
    select count(value) from TableA group by value
    
    Oh my head is not working today.

    Cheers ;)

    That will only return the following:

    4
    3

    You need to add in the VALUE column:

    SELECT VALUE, count(value) from TableA group by value

    /pedantic :)


  • Closed Accounts Posts: 448 ✭✭ve


    LOL, don't worry. I was just trying to keep the focus of my problem as concise as possible. I have it all working in place now.
    My table wasn't actually called TableA, or the column called value. It was merely created to illustrate the problem at hand. Muhahahahaha. /runs ;)

    Thanks for all the help folks.


Advertisement