Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
clicksデータベースにandという行を持つテーブルがありますuser。すべての行の値をカウントしたいWHERE user='Oliver'
clicks
user
WHERE user='Oliver'
私はこれを試しました:
SELECT count(clicks) FROM `stats` WHERE user="Oliver"
ただし、上記のステートメントが当てはまる行の数をカウントするだけです。私が欲しいのは、すべての行のクリックの値を数えることですwhere user="Oliver"
where user="Oliver"
どうやってやるの?
SUM 関数が必要です。
SELECT SUM(clicks) FROM stats WHERE user="Oliver" GROUP BY user;
clicksこれにより、列内のすべての行のすべての値が合計されますuser="Oliver"。
user="Oliver"
参考:GROUP BY(集計)関数