/* 
You are managing a university database containing information about students and the courses they are enrolled in. The `enrollments` table has the following schema:  

| Column Name  | Data Type     | Description                   |  
|--------------|---------------|-------------------------------|  
| student_id   | INT           | Unique ID for each student    |  
| student_name | VARCHAR(100)  | Full name of the student      |  
| course_id    | INT           | Unique ID for each course     |  
| course_name  | VARCHAR(100)  | Name of the course            |  

Task:  
1. For each student, list all the courses they are enrolled in, separated by a semicolon (`;`).  
2. Display only students who are enrolled in three or more courses.  
3. The result should include:  
   • `student_name`  
   • `courses_list` (a semicolon-separated list of course names)  
   • `total_courses`  

Expected Output:  

| student_name   | courses_list                                | total_courses |  
|----------------|---------------------------------------------|---------------|  
| Alice Johnson  | Math 101; Physics 102; Chemistry 103        | 3             |  
| Bob Smith      | English 104; History 105; Art 106; Math 101 | 4             |  
*/

CREATE TABLE enrollments (
    student_id INT,
    student_name VARCHAR(100),
    course_id INT,
    course_name VARCHAR(100)
);

INSERT INTO enrollments (student_id, student_name, course_id, course_name) VALUES
(1, 'Alice Johnson', 101, 'Math 101'),
(1, 'Alice Johnson', 102, 'Physics 102'),
(1, 'Alice Johnson', 103, 'Chemistry 103'),
(2, 'Bob Smith', 104, 'English 104'),
(2, 'Bob Smith', 105, 'History 105'),
(2, 'Bob Smith', 106, 'Art 106'),
(2, 'Bob Smith', 107, 'Math 101'),
(3, 'Charlie Brown', 108, 'Biology 107'),
(3, 'Charlie Brown', 109, 'Computer Science 108'),
(4, 'Diana Prince', 110, 'Psychology 109');

SELECT 
    student_name,
    GROUP_CONCAT(course_name SEPARATOR '; ') AS courses_list,
    COUNT(course_id) AS total_courses
FROM enrollments
GROUP BY student_id, student_name
HAVING total_courses >= 3;

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: