SELECT分で、WHEREで条件を指定して取り出したデータを、COUNTしたり、SUM(合計)したり、AVG(平均)したりする方法。 まずは、サンプルデータを作ります。 CREATE TABLE test ( id BIGINT , name TEXT , age SMALLINT ) ; INSERT INTO test (id, name, age) VALUES ('1', 'nagatomo', '31'); INSERT INTO test (id, name, age) VALUES ('2', 'yoshida', '28'); INSERT INTO test (id, name, age) VALUES ('3', 'honda', '30'); INSERT INTO test (id, name, age) VALUES ('4', 'okazaki', '31')
![MySQL 条件つきでCOUNT、SUM、AVGする | テクニカルノート](https://cdn-ak-scissors.b.st-hatena.com/image/square/b9a5e548dcfcbaa4b4ed7483ffbaf18733cd8e96/height=288;version=1;width=512/https%3A%2F%2Faccelboon.com%2Ftn%2Fwp-content%2Fthemes%2Fcocoon-master%2Fscreenshot.jpg)