create table t
( id int auto_increment primary key,
send_time datetime not null,
user varchar(100) not null
);
insert t (send_time,user) values
('2016-07-24 00:00:00', 'a'),
('2016-07-24 01:00:00', 'b'),
('2016-07-23 12:00:00', 'a'),
('2016-07-22 12:00:00', 'a'),
('2016-07-21 12:00:00', 'a'),
('2016-07-20 12:00:00', 'a'),
('2016-07-19 12:00:00', 'b'),
('2016-07-18 11:00:00', 'c');
クエリ:それは最後の3日間ローリングする必要がある場合
select date(send_time),count(distinct user)
from t
group by date(send_time)
order by date(send_time) desc;
+-----------------+----------------------+
| date(send_time) | count(distinct user) |
+-----------------+----------------------+
| 2016-07-24 | 2 |
| 2016-07-23 | 1 |
| 2016-07-22 | 1 |
| 2016-07-21 | 1 |
| 2016-07-20 | 1 |
| 2016-07-19 | 1 |
| 2016-07-18 | 1 |
+-----------------+----------------------+
7 rows in set (0.00 sec)
、ちょうど最後にLIMIT 3
を行います。
人々のためにデータを設定するために時間をかけてください。他の人があなたを助けるように助けてください写真はカウントされません。
はそれについて何を転がしていると? – Drew
素晴らしい!何を試しましたか? –
幸いにもストロベリーによるロールバック:p – Drew