Home Forums SQL Server 2005 T-SQL (SS2K5) tsql query for counting a 'grouped by' and a where clause RE: tsql query for counting a 'grouped by' and a where clause

  • I've managed to get thus far:

    I've added my employer table and used a left join.

    I can count all the users in total (sum of all users for that employer e.g. global users + superusers), but not just superusers.

    using this code:

    SELECT e.EmployerName, { fn IFNULL(x.super_userCnt, 0) } AS super_userCnt

    FROM dbo.mytableEmployer e LEFT OUTER JOIN

    (SELECT employerName, COUNT(*) AS super_userCnt

    FROM employerSuper_Users

    GROUP BY employerName) x ON e.EmployerName = x.employerName

    if I add a where clause - it either says invalid column name or incorrect syntax