mysql> desc produksi;
+------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+-------+
| id_pegawai | char(4) | YES | | NULL | |
| id_barang | char(4) | YES | | NULL | |
+------------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> select * from produksi;
+------------+-----------+
| id_pegawai | id_barang |
+------------+-----------+
| PEG1 | BAR1 |
| PEG1 | BAR2 |
| PEG1 | BAR3 |
| PEG2 | BAR1 |
| PEG2 | BAR2 |
| PEG2 | BAR3 |
| PEG2 | BAR4 |
| PEG3 | BAR1 |
| PEG3 | BAR2 |
| PEG3 | BAR3 |
| PEG3 | BAR4 |
| PEG3 | BAR5 |
| PEG3 | BAR6 |
+------------+-----------+
13 rows in set (0.00 sec)
Mencari Jumlah dengan Query Count :
mysql> select count(id_barang) hasilcount from produksi group by id_pegawai;
+------------+
| hasilcount |
+------------+
| 3 |
| 4 |
| 6 |
+------------+
3 rows in set (0.00 sec)
Mencari Minimal dari hasil count dengan Query Min :
mysql> select min(hasilcount) from (select count(id_barang) hasilcount from produksi group by id_pegawai) as minimal;
+-----------------+
| min(hasilcount) |
+-----------------+
| 3 |
+-----------------+
1 row in set (0.00 sec)
EmoticonEmoticon