1. Hey Guest Did you know you can win an Honor 10 phone worth ₹33,000 and an additional ₹70,000 in paytm vouchers, just by replying to some threads and taking part in the discussions happening in the Honor Hub?

    What are you waiting for? Start commenting and start winning! Remember to read the instructions posted here.

    Dismiss Notice

Need help with mySQL statement

Discussion in 'Programming' started by Sridhar_Rao, Jun 14, 2009.

Thread Status:
Not open for further replies.
  1. Sridhar_Rao

    Sridhar_Rao New Member

    Joined:
    Feb 16, 2007
    Messages:
    355
    Likes Received:
    1
    Trophy Points:
    0
    I need help with SQL statement. Here is the structure of the table

    +-------+---------------+
    | slno | labno |
    +-------+---------------+
    | 1 | 5 |
    +-------|---------------|
    | 1 | 6 |
    +-------|---------------|
    | 2 | 7 |
    +-------|---------------|
    | 3 | 8 |
    +-------|---------------|
    | 3 | 9 |
    +-------|---------------|
    | 3 | 10 |
    +-------|---------------|
    | 4 | 11 |
    +-------|---------------|

    I need the output something like this:

    +---------+---------+
    | times | Nos |
    +---------+---------+
    | 3 | 1 | a*
    +---------+---------+
    | 2 | 1 | b*
    +---------+---------+
    | 1 | 2 | c*
    +---------+---------+

    a* i.e number of cases where slno is present 3 times (e.g slno 3 is present thrice and it is the only slno to be present thrice)
    b* i.e number of cases where slno is present 2 times (e.g slno 1 is present twice and it is the only slno to be present twice)
    c* i.e number of cases where slno is present once (e.g slno 2 & 4 are present only once and only two slno are present once)
     
  2. vamsi360

    vamsi360 Always confused

    Joined:
    May 10, 2008
    Messages:
    348
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Garden City
    use COUNT(x) statement in WHERE clause
     
Thread Status:
Not open for further replies.

Share This Page