Reputation: 11
App usage data are kept in the following table:
Table sessions
:
id INTEGER PRIMARY KEY,
userId INTEGER NOT NULL,
duration DECIMAL NOT NULL
I need a query that selects userId and average session duration for each user who has more than one session.
Upvotes: 0
Views: 4874
Reputation: 13506
SELECT userId,AVG(duration),count(id) as num
FROM sessions GROUP BY userId HAVING count(id) > 0
Upvotes: 1
Reputation: 522292
I would write this as:
SELECT userId, AVG(duration)
FROM sessions
GROUP BY userId
HAVING COUNT(*) > 1;
Upvotes: 6