sql - Number of students and courses in a location -


i trying build statement give me output of 3 columns. location, sections (count of sections in location) , students (count of students in location). in statement below sub queries give correct counts separately; however, when add top select statement have of counts show under student column location listed twice.

select distinct location, student from(     select location, count(student_id) student     section s inner join enrollment e     on s.section_id = e.section_id     group location union     select location, count(section_no) sections     section      group location     order location); 

my results what trying get

if want 3 columns, need specify them in sql statement. easiest way count(distinct):

select s.location, count(distinct s.section_id) numsections,        count(student_id) student section s inner join      enrollment e      on s.section_id = e.section_id group s.location; 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -