Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- go
- drop function passedCheck
- go
- create function passedCheck (@studentno int)
- returns Char(15)
- as
- BEGIN
- declare @res char(15)
- -- her skal du indsætte din T-SQL kode
- declare @average decimal(10,2)
- declare @sum decimal(10,2)
- declare @avgThree decimal(10,2)
- declare @bottomtwo decimal(10,2)
- declare @strangeAvg decimal(10,2)
- SELECT @average = avg(grade * 1.0) from grades WHERE grades.studentno = @studentno
- SELECT @avgThree = avg(y.grade * 1.0) from (select TOP 3 grade from grades WHERE grades.studentno = @studentno ORDER BY grade desc) as y
- SELECT @bottomtwo = sum(x.grade * 1.0) from (select TOP 2 grade from grades WHERE grades.studentno = @studentno ORDER BY grade asc) as x
- SELECT @strangeAvg = @avgThree + @bottomtwo
- IF @average > 5.5 AND @strangeAvg > 13
- select @res = 'PASSED'
- ELSE
- select @res = 'FAILED'
- RETURN @res
- END
- go
- select name,dbo.passedCheck(studentno)
- from student
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement