253,400,626,799 19

MySQLで月別、日別、時間、曜日別にレコード数を集計する方法

<p>月毎、日毎、時間、曜日毎にレコード数を集計をする。</p> <h2>月毎</h2> <p><code>SELECT DATE_FORMAT(regist_time, '%Y-%m') as regist_time, COUNT(*) as count FROM users GROUP BY DATE_FORMAT(regist_time, '%Y%m'); </code></p> <h2>日毎</h2> <p><code>SELECT DATE_FORMAT(regist_time, '%Y-%m-%d') as regist_time, COUNT(*) as count FROM users GROUP BY DATE_FORMAT(regist_time, '%Y%m%d'); </code></p> <p><strong>■時間毎</strong></p> <pre>SELECT DATE_FORMAT(regist_time, '%H') as regist_time, COUNT(*) as count FROM users GROUP BY DATE_FORMAT(regist_time, '%H'); </pre> <p><strong>■曜日毎</strong></p> <pre>SELECT DATE_FORMAT(regist_time, '%w') as regist_time, COUNT(*) as count FROM users GROUP BY DATE_FORMAT(regist_time, '%w');</pre>

Info

Editor
Updated
Title
MySQLで月別、日別、時間、曜日別にレコード数を集計する方法
Keywords
Description
Category
Language
Length
1053 Bytes
Characters
608 Chars

Votes

If you want to vote, please Sign in.

Review

Create review

No reviews.