select col0, count(col1) from table0 group by type;

5337 ワード


mysql> select * from hero_list;
+----+------+---------+
| no | type | name    |
+----+------+---------+
|  0 |    1 | ABC     |
|  1 |    1 | DEF     |
|  2 |    1 | ZEF     |
|  3 |    2 | ALT     |
|  4 |    2 | KEVIN   |
|  5 |    2 | DRAGOON |
|  6 |    1 | as      |
|  7 |    1 | zo      |
+----+------+---------+
8 rows in set (0.00 sec)

mysql> select type, count(name) as cnt from hero_list group by type;
+------+-----+
| type | cnt |
+------+-----+
|    1 |   5 |
|    2 |   3 |
+------+-----+
2 rows in set (0.01 sec)
typeとcount(name)を選択します.
from hero listテーブルでは、
group by type; typeでこの2つを組み合わせて表示します
結果
表示する列はtypeとcount(name)列です.
tableはhero listを使用します.
group by type、typeを標準パケットとする.
typeの値は1,2、1つの包帯、2つの包帯しかありません
typeとcount(name)が表示され、typeが2回表示され、結果がtypeにグループ化されます.
typeで見たい
typeを基準にバンドルされているので、typeを外して見せると結果だけ見てtypeにバンドルされているかどうか分かりません.
typeを削除し、sql文を作成します.select no, count(name) from hero_list group by type;実行後...ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'hero.hero_list.no' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_byこのようなエラーが発生しました.