Home > database >  Newcomer for help, to specify queries
Newcomer for help, to specify queries

Time:09-17

Database tables:

Students table
Name, sex, age, birthday, class
The teacher table
Name, sex, age, course, class
Class table
The class name, grade level


1. The query name all the students

2. A query specifies the number of students in the class

3. The average age of the students in the query class, age, the largest minimum age student

4. The query class the number of boys, girls

CodePudding user response:

1. The query name all the students
Students SELECT s. * FROM table table T S JOIN teachers ON t. class=s. class WHERE t. name=? ;
2. A query specifies the number of students in the class
SELECT COUNT (0) the number of students FROM the student table WHERE s. S class=? ;
3. The average age of the students in the query class, age, the largest minimum age student
SELECT AVG average age (age), MAX maximum age (age), MIN (age) minimum age FROM students table WHERE s. S class=? ;
4. The query classes, the number of boys girls number
SELECT SUM (DECODE (gender, 'male', 1, 0)) number of boys, the SUM (DECODE (gender, 'female', 1, 0)) girl number FROM students table WHERE s. S class=? ;

CodePudding user response:

Recommend a course of graphic, from entry to the proficient in SQL,
  • Related