sql server - SQL Query returns one result, does not return 0 or NULL result -


i trying query list advisers , provide count of active students each. can list advisers have 1 student, exclude more 1, can not return advisers 0 or null count.

select advisors.advisorid, advisors.firstname, advisors.lastname, count(case students.isactive when '1' 1 else null end) "number of students" advisors, students advisors.advisorid=students.advisorid group advisors.advisorid, advisors.firstname, advisors.lastname having count(case students.isactive when '1' 1 else null end)='1' 

counts active studnets, , returns advisor list advisor 1 student, advisers 0 students come blank. missing?

select advisors.advisorid, advisors.firstname, advisors.lastname, count(case students.isactive when '1' 1 else null end) "number of students" advisors, students advisors.advisorid=students.advisorid group advisors.advisorid, advisors.firstname, advisors.lastname having count(case students.isactive when '1' 1 else null end) null  

comes column names , no data. have double checked tables advisor table has 3 entries, 1 has 2 active students , 1 inactive 0 or 1 using bit, 1 has no students, , 1 has one.

using <= 1 or < 1 result in blank data.

please use ansi join syntax

select    advisors.advisorid,            advisors.firstname,            advisors.lastname,            count(case students.isactive when '1' 1 else null end) "number of active students"      advisors left join students on        advisors.advisorid=students.advisorid group  advisors.advisorid,            advisors.firstname,            advisors.lastname having count (students.advisorid) = 1 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -