MVC5 HTML 将列设为 table header?

MVC5 HTML make column as table header?

在我的数据库中查看这个 table:

==============================
|^student |^Subject |^Result |
==============================
| name1   | math    | pass   |
==============================
| name1   | physics | pass   |
==============================
| name1   | Biology | faille |
==============================
| name2   | math    | pass   |
==============================
| name2   | physics | faille |
==============================
| name2   | Biology | pass   |
==============================

通过使用 MVC 5、HTML 和 SQL Server 2017,我可以在索引页中将其制作成这样吗:

======================================
|^student | Math | Physics | Biology |
======================================
| name1   | pass | pass    | faille  |
======================================
| name2   | pass | faille  | pass    |
======================================

提前致谢。

您可以进行条件聚合:

select student,
    max(case when subject = 'math'    then result end) math,
    max(case when subject = 'physics' then result end) physics,
    max(case when subject = 'biology' then result end) biology
from mytable
group by student