在MySql中选择一个双向表 [英] Select a two-way table in MySql
问题描述
我有三个MySql表:
I have three MySql tables:
学生-学生编号,学生姓名
Students - StudentId, StudentName
评估-评估ID,评估名称
Assessments - AssessmentId, AssessmentName
结果-学生编号,评估编号,成绩
Results - StudentId, AssessmentId, Grade
我无法预先确定学生或评估的数量,因为它们是由用户创建的.
如何选择双向表格,显示所有学生的评估结果(行和列的数量不确定):
How can I select a two-way table, showing the results of all students' assessments (which will have an unpredetermined number of rows and columns):
|--------|---------|---------|---------|---------|---------|
|User |Test A |Test B |Test C |Test D |Test E |
|--------|---------|---------|---------|---------|---------|
|Alex |A |A |C |Null |F |
|Ben |Null |D |A |Null |Null |
|--------|---------|---------|---------|---------|---------|
我希望通过SQL select或使用ASP.NET中的LINQ to Entities来执行此操作,如果该方法具有实现此目的的有效方法.
I am looking to do this either in a SQL select, or using LINQ to Entities in ASP.NET, if that has an efficient method for achieving the same.
谢谢.
推荐答案
您无法在单个SQL查询中实现此目的.您将需要一个函数,该函数将生成具有可变列的结果集,然后从中进行选择.
You cannot achieve this in a single SQL query. You will need a function that will generate a result-set with variable columns and then make a select from it.
这篇关于在MySql中选择一个双向表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!