How to build sql query in this situation:
I have to tables (only showing table columns)
Table one
- Users -> ID, First name, Last name....
Table two
– events -> ID, UserID, statID
I want to get sql results like this:
ID,
First name,
Last name,
count(from table event where stat == 11 and (between date1 and date2)),
count(from table event where stat =? 8 and (between date1 and date2))
Please help me
This is a sql server based solution:
Here I used a
LEFT JOIN
to give you results for all users even if they didn't have any event. If you interested only in those with event id then you need to useINNER JOIN
.