TSQL How to calculate exam result based on values from multiple rows [closed]

If you have minimum mark criteria for each subject, then check it with a CASE expression. And then use another CASE expression to check whether the no. pass criteria is matching with the total no.

Query

declare @minMark as int = 35; -- change accordingly

select [sid],
case when (
    sum(case when [marks] >= @minMark then 1 else 0 end) = count(*)
) then 'Pass' else 'Fail' end as [stat]
from [your_table_name]
group by [sid];