MVC5 HTML将列作为表头?
Posted
技术标签:
【中文标题】MVC5 HTML将列作为表头?【英文标题】:MVC5 HTML make column as table header? 【发布时间】:2021-01-23 21:17:45 【问题描述】:查看我数据库中的这张表:
==============================
|^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 |
======================================
提前谢谢你。
【问题讨论】:
当然。枢轴,或分组,或挑选你的毒药。请更加具体和详细,因为您如何做到这一点取决于您的消费者 - 存储过程、实体框架或其他一些 ORM 或普通查询。 【参考方案1】:你可以做条件聚合:
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
【讨论】:
以上是关于MVC5 HTML将列作为表头?的主要内容,如果未能解决你的问题,请参考以下文章