简体   繁体   English

SQL查询在哪里和不同

[英]SQL query with where and distinct

I have the following sql query which gets back unique days from a column of time stamp values for a particular user. 我有以下sql查询,该查询从特定用户的时间戳值列中获取唯一天数。 What I am trying to get back is the count of timestamp values for each unique day for a particular user. 我想找回的是特定用户每一天的时间戳记值计数。

 select distinct DAY(time) from users_has_activities
 where usersID = 47;

Using a count COUNT(column_name) with a GROUP BY should do the trick: 将计数COUNT(column_name)与GROUP BY一起使用应该可以解决问题:

SELECT DAY(time), COUNT(DAY(time))
FROM users_has_activities
WHERE usersID = 47
GROUP BY DAY(time);
select count(distinct DAY(time) )
from users_has_activities
where usersID = 47;

Use groupby clause to get count so it would loook something like followin: 使用groupby子句获取计数,因此它会看起来像followin:

select DAY(time), count(1)
from users_has_activities
group by DAY(time);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM