Home  >  Article  >  Backend Development  >  mysql如何查今天登录了多少人

mysql如何查今天登录了多少人

WBOY
WBOYOriginal
2016-06-06 20:32:161027browse

每次登录都会生成一条log记录,包含登录时间和用户的userId
我应该怎么写sql才能查出 今天 都多少人登录过?
重复的userId不记录?

<code>"select count(*) from log_login where login_time > '{date('Y-m-d')}' "
</code>

不行呀。。

回复内容:

每次登录都会生成一条log记录,包含登录时间和用户的userId
我应该怎么写sql才能查出 今天 都多少人登录过?
重复的userId不记录?

<code>"select count(*) from log_login where login_time > '{date('Y-m-d')}' "
</code>

不行呀。。

<code>select count(DISTINCT userId) from log_login where DATE_FORMAT(login_time, '%Y-%m-%d')=DATE_FORMAT(now(), '%Y-%m-%d')
</code>

终于碰到 我能回答的问题了

where 时间 >= 2015-7-3 00:00:00 and 时间

应该就ok了

select count(distinct userid) from log_login where login_time >='今天' and login_time 或者用group by userid

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn