DIGIT-ARC read-only archive · snapshot: July 23, 2026

Need help with mySQL statement

2 posts · originally from https://geek.digit.in/community/threads/need-help-with-mysql-statement.118326/

Sridhar_Rao
Sridhar_Rao Original post #1
Jun 14, 2009 at 2:01 PM
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)
vamsi360
Jun 15, 2009 at 12:09 PM
use COUNT(x) statement in WHERE clause