Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

GROUP BY CLAUSE

DESCRIBE EMPLOYEE

GROUP BY
mysql> select count(Ssn),Dno
-> from employee63
-> group by Dno;
+------------+------+
| count(Ssn) | Dno |
+------------+------+
| 4 | 5 |
| 1 | 1 |
| 3 | 4 |
+------------+------+
3 rows in set (0.00 sec)
GROUP BY HAVING CLAUSE

DESCRIBE WORKS_ON
mysql> select * from works_on63;
+-----------+-----+-------+
| Essn | Pno | Hours |
+-----------+-----+-------+
| 123456789 | 1 | 33 |
| 123456789 | 2 | 8 |
| 333445555 | 2 | 10 |
| 333445555 | 3 | 10 |
| 333445555 | 10 | 10 |
| 453453453 | 1 | 20 |
| 453453453 | 2 | 20 |
| 666884444 | 3 | 40 |
| 888665555 | 20 | NULL |
| 987654321 | 20 | 15 |
| 987654321 | 30 | 20 |
| 987987987 | 10 | 35 |
| 987987987 | 30 | 5 |
| 999887777 | 10 | 10 |
| 999887777 | 30 | 30 |
+-----------+-----+-------+
15 rows in set (0.00 sec)

GROUP BY HAVING
mysql> select Pno,sum(hours)
-> from works_on63
-> group by Pno
-> having count(Pno);
+-----+------------+
| Pno | sum(hours) |
+-----+------------+
| 1 | 53 |
| 2 | 38 |
| 3 | 50 |
| 10 | 55 |
| 20 | 15 |
| 30 | 55 |
+-----+------------+
6 rows in set (0.00 sec)

You might also like