Skip to content
Project: Analyzing Students' Mental Health in SQL
  • AI Chat
  • Code
  • Report
  • Does going to university in a different country affect your mental health? A Japanese international university surveyed its students in 2018 and published a study the following year that was approved by several ethical and regulatory boards.

    The study found that international students have a higher risk of mental health difficulties than the general population, and that social connectedness (belonging to a social group) and acculturative stress (stress associated with joining a new culture) are predictive of depression.

    Explore the students data using PostgreSQL to find out if you would come to a similar conclusion for international students and see if the length of stay is a contributing factor.

    Here is a data description of the columns you may find helpful.

    Field NameDescription
    inter_domTypes of students (international or domestic)
    japanese_cateJapanese language proficiency
    english_cateEnglish language proficiency
    academicCurrent academic level (undergraduate or graduate)
    ageCurrent age of student
    stayCurrent length of stay in years
    todepTotal score of depression (PHQ-9 test)
    toscTotal score of social connectedness (SCS test)
    toasTotal score of acculturative stress (ASISS test)
    Spinner
    DataFrameavailable as
    students
    variable
    -- Run this code to save the CSV file as students
    SELECT * 
    FROM 'students.csv';
    Spinner
    DataFrameavailable as
    df
    variable
    -- Start coding here...
    /*Count the number of records*/
    SELECT COUNT(*) AS total_records
    FROM students;
    
    /*Count by student type*/
    SELECT inter_dom, COUNT(*) As count_inter_dom
    FROM students
    GROUP BY inter_dom;
    
    /*Count by student type*/
    SELECT inter_dom, COUNT(*) As count_inter_dom
    FROM students
    GROUP BY inter_dom;
    
    /*Count of international students*/
    SELECT COUNT(*) As student_type_inter
    FROM students
    WHERE inter_dom = 'Inter';
    
    /*Count of domestic students*/
    SELECT COUNT(*) As student_type_dom
    FROM students
    WHERE inter_dom = 'Dom';
    
    /*Count of entries with null student type*/
    SELECT COUNT(*) As student_type_null
    FROM students
    WHERE inter_dom IS NULL;
    
    /*Summary stats for _phq for all students*/
    SELECT MIN(todep) As min_phq, MAX(todep) As max_phq,
    ROUND(AVG(todep), 2) As avg_phq
    FROM students;
    
    /*Summary stats for _scs for all students*/
    SELECT MIN(tosc) As min_scs, MAX(tosc) As max_scs, ROUND(AVG(tosc), 2) As avg_scs
    FROM students;
    
    /*Summary stats for _as for all students*/
    SELECT MIN(toas) As min_as, MAX(toas) As max_as, ROUND(AVG(toas), 2) As avg_as
    FROM students;
    
    /*Summary stats for _as for international students only*/
    SELECT inter_dom, MIN(todep) As min_tophq, MAX(todep) As max_tophq,
    ROUND(AVG(todep), 2) As avg_phq
    FROM students
    WHERE inter_dom = 'Inter'
    GROUP BY inter_dom;
    
    SELECT inter_dom, MIN(tosc) As min_sc, MAX(tosc) As max_sc,
    ROUND(AVG(tosc), 2) As avg_sc
    FROM students
    WHERE inter_dom = 'Inter'
    GROUP BY inter_dom;
    
    SELECT inter_dom, MIN(toas) As min_as, MAX(toas) As max_as,
    ROUND(AVG(toas), 2) As avg_as
    FROM students
    WHERE inter_dom = 'Inter'
    GROUP BY inter_dom;
    
    
    /*Impact of length of stay*/
    SELECT  
    stay, 
    ROUND(AVG(todep), 2) As average_phq, 
    ROUND(AVG(tosc), 2) As average_scs,
    ROUND(AVG(toas), 2) As average_as
    FROM students
    WHERE inter_dom = 'Inter'
    GROUP BY stay
    ORDER BY stay DESC;