日期:2014-05-16  浏览次数:20674 次

这条sql语句怎么写 是高手的进来看看
我有一个表 reports_user 
  字段如下:
id time activer register lastLoginer(time这一天登陆的用户) (其他的字段不要考虑)
218 20111109 23 56 100
217 20111203 0 0 0
216 20111204 0 0 0
215 20111205 0 0 0
214 20111206 0 0 0
213 20111207 0 0 0
212 20111208 0 0 3
211 20111209 0 0 0
210 20111210 0 0 0
209 20111211 0 0 0
208 20111212 0 0 0
207 20111213 1 1 1
206 20111214 1 1 1
205 20111215 0 0 0
204 20111216 23 45 100
203 20111217 0 0 0
202 20111218 0 0 0
201 20111219 23 100 132
200 20111220 34 123 450
199 20111221 0 0 0
198 20111222 0 0 0
197 20111223 0 0 0
196 20111224 12 45 123
195 20111225 34 100 254
194 20111226 23 45 100
我的要求是输出如下的列:
allLastLoginer: (在time之前所有登陆过得用户) (包括time这一天)
time:    时间
lastLoginer: 在time这一天登陆过得用户
表如下
time lastLoginer allLastLoginer (包括time这一天所有登陆过得用户)
20111223 23 56

------解决方案--------------------
select time,count(*) as lastLoginer,
(select count(*) from tt where time<=a.time) as allLastLoginer
from tt a
group by time