Student Database Query Examples
Student Database Query Examples
The use of a subquery, like 'SELECT name, age FROM student WHERE age=(SELECT MIN(age) FROM student);', allows the identification of specific data points (e.g., name) associated with the minimum age, which cannot be directly achieved with a simple aggregation function alone . It selects rows matching the minimal condition, aligning broader queries with more contextually relevant information than executing two separate queries.
The query 'SELECT * FROM student WHERE city='ahmedabad' OR City='surat';' selects students from either Ahmedabad or Surat. This combined filtering enables localized demographic analysis, vital in resource allocation or educational policy development .
Use the query 'SELECT SUM(Marks) FROM student WHERE City='vadodara';' to sum the marks of students from Vadodara. The WHERE clause restricts the selection to rows from the specified city, enabling focused aggregation .
To find the student with the highest marks, use the query 'SELECT name FROM student WHERE Marks=(SELECT MAX(Marks) FROM student);'. This subquery strategy identifies the maximum mark and filters the student(s) who have this score .
The query 'SELECT Course, COUNT(Course) as student_count FROM student GROUP BY Course;' groups students by their courses and counts the students in each, effectively detailing course populations .
The query 'SELECT * FROM student WHERE gender='female';' isolates female students by filtering on the gender column. This practice helps target specific demographic information or analysis within databases .
The query 'SELECT Course, AVG(marks) as marks_average FROM student GROUP BY Course;' allows you to compute the average marks for students in each course. It groups the entries by the course column and calculates the average marks for each group .
The query 'SELECT name, marks FROM student WHERE Marks BETWEEN 80 AND 90;' fetches students whose marks fall within 80 to 90. This targeted filtering supports focused analytics in performance band assessments, crucial for benchmarking or support interventions .
By using 'SELECT gender, COUNT(gender) AS count_gender FROM student GROUP BY gender;', one can comprehend gender distribution among students, facilitating studies on gender parity in education or potential biases in enrollment trends .
To achieve this, you can use the query 'SELECT name, marks FROM student WHERE Marks > 80 ORDER BY Marks DESC;'. This query filters students who scored above 80 marks and orders the results from highest to lowest marks .