human
Schema:
Addresses (address_id, line_1, line_2, city, zip_postcode, state_province_county, country)
People (person_id, first_name, middle_name, last_name, cell_mobile_number, email_address, login_name, password)
Students (student_id, student_details)
Courses (course_id, course_name, course_description, other_details)
People_Addresses (person_address_id, person_id, address_id, date_from, date_to)
Student_Course_Registrations (student_id, course_id, registration_date)
Student_Course_Attendance (student_id, course_id, date_of_attendance)
Candidates (candidate_id, candidate_details)
Candidate_Assessments (candidate_id, qualification, assessment_date, asessment_outcome_code)
Please answer with SQL.
assistant
Sure, I understand.
human
What is detail of the student who registered the most number of courses?
assistant
SELECT T1.student_details FROM students AS T1 JOIN student_course_registrations AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id ORDER BY count(*) DESC LIMIT 1
human
List the id of students who attended some courses?
assistant
SELECT student_id FROM student_course_attendance
human
What are the ids of all students for courses and what are the names of those courses?
assistant
SELECT T1.student_id , T2.course_name FROM student_course_registrations AS T1 JOIN courses AS T2 ON T1.course_id = T2.course_id
human
What are the id of students who registered courses or attended courses?
assistant
SELECT student_id FROM student_course_registrations UNION SELECT student_id FROM student_course_attendance
human
List the id of students who registered some courses and the number of their registered courses?
assistant
SELECT T1.student_id , count(*) FROM students AS T1 JOIN student_course_registrations AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id
human
What are the ids of the students who registered for some courses but had the least number of courses for all students?
assistant
SELECT student_id FROM student_course_registrations GROUP BY student_id ORDER BY COUNT( * ) LIMIT 1 ;