Getting the above average student from database

后端 未结 5 1321
别跟我提以往
别跟我提以往 2021-01-15 18:40

I\'ve created a view that contains:

 student_full_name    subject_code    result
 Jennifer Higgins     CS1234          81
 Jennifer Higgins     CS1235                


        
5条回答
  •  天涯浪人
    2021-01-15 19:16

    Every problem as a solution, I created a table

    CREATE TABLE STUD
    (SNAME varchar(20),
     SCODE NUMBER    PRIMARY KEY,
     MARKS NUMBER(4,2))
    

    Inserted values

    SNAME   SCODE   MARKS
    --------------------
    SAM     1001    90
    VAS     1001    80
    SAM     1002    60
    ANAND   1001    80
    VAS     1002    70
    ANAND   1002    50
    

    Query is

    SELECT SNAME,AVG(MARKS) FROM STUD GROUP BY SNAME HAVING AVG(MARKS)>=
    (SELECT MAX(MARKS ) FROM STUD WHERE SNAME='VAS')
    

提交回复
热议问题