0

我正在尝试创建一个表,该表输出用户列表以及他们登录的次数。

每次有人登录时都会在表中创建一个新行,因此一个用户有多个行。

现在,我正在尝试使用以下语句来提取数据:

SELECT * FROM logins GROUP BY user ORDER BY timestamp DESC

哪个工作正常,但现在我的 HTML 表中有一个列应该显示用户登录的次数。我如何计算每个组中的行数?

4

5 回答 5

1

试试这个:

SELECT *, COUNT(*) AS count FROM logins GROUP BY user ORDER BY timestamp DESC
于 2012-10-31T11:00:31.890 回答
1
SELECT user, count(timestamp) as login_count 
FROM logins
GROUP BY user
ORDER BY login_count DESC

获取按登录次数排序的用户

于 2012-10-31T11:00:36.957 回答
1

使用 count()... 试试这个

SELECT *, COUNT(*) as totalcounts FROM logins GROUP BY user ORDER BY timestamp DESC

COUNT() 函数返回与指定条件匹配的行数。

于 2012-10-31T11:01:11.630 回答
1
SELECT user,count(*) as NoOfTimes
 FROM logins 
GROUP BY user 
ORDER BY timestamp DESC
于 2012-10-31T11:01:25.483 回答
1

使用COUNT

SELECT user, COUNT(user) 'How Many Times he logged in'
FROM logins 
GROUP BY user 
ORDER BY timestamp DESC
于 2012-10-31T11:01:31.817 回答