This is my requirement.
I have a table A which has names, a table B which has the statistics of the number of users visting the sites(whose names are in A) and a table C which has the company information. I need to write a SQL statement to get all the names in tableA and the number of times it was visited from table B. (Even if there is no visit to a site, i should get the name and the count as 0). This is the SQL i have written, but am not getting all the names from table A. Any help would be appreciated.
select B.name, count(*) from A left join B on A.name = B.name left JOIN C ON B.id = A.id and C.user_id IN (select user.user_id from user where company_id=115) where B.init_time between @startdate AND @enddate GROUP BY B.name
I have a table A which has names, a table B which has the statistics of the number of users visting the sites(whose names are in A) and a table C which has the company information. I need to write a SQL statement to get all the names in tableA and the number of times it was visited from table B. (Even if there is no visit to a site, i should get the name and the count as 0). This is the SQL i have written, but am not getting all the names from table A. Any help would be appreciated.
select B.name, count(*) from A left join B on A.name = B.name left JOIN C ON B.id = A.id and C.user_id IN (select user.user_id from user where company_id=115) where B.init_time between @startdate AND @enddate GROUP BY B.name