0

I'm trying to create a table which outputs a list of users and how many times they've logged in.

A new row in the table is created every time that someone logs in so there is multiple rows for one user.

Now, I'm trying using the following statement to pull the data out:

SELECT * FROM logins GROUP BY user ORDER BY timestamp DESC

Which is working fine but now there is a column in my HTML table which should show how many times the user has logged in. How do I go about counting the amount of rows in each group?

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 に答える