SELECT DATE( created_at ), ( SELECT count( * ) FROM member m2 WHERE DATE( m2.created_at ) <= DATE( m1.created_at ) ) FROM member m1
2. 透過變數方式累積加總
1 2 3 4 5 6 7 8 9 10 11 12 13 14
SET @count = 0; SELECT today.date, @count := @count + today.count AS today_register_num FROM ( SELECT DATE( created_at ) AS date, count( member.id ) AS count FROM member GROUP BY DATE( createtime ) ) today