如何像平面表一样进行分组 linq 查询
你好 我想为这样的表创建一个查询: 1.我有一个多个问题,我想计算对多个问题结果的每个答案的每个响应的数量,并在格式如下的查询中显示它们: 1.ID 2.问题短语 3.q1 4.q2 5.q3 6.q4 7.count1 8.count2 9.count3 10.count4 我已经创建了一个像这样的 linq 查询,它来自于答案表,之后我可以将它们与 ID 连接到问题表并获取短语和其他:
var q4 = (from x in LinqDB.PTAs
where x.PTID == int.Parse(DropDownListPeriodID.SelectedValue) &&
x.PTUser.PTUserID >= ID1 && x.PTUser.PTUserID <= ID2
group x by x.PTQID into GRPA //& x.PTAID
select new {
GRPA.Key,
A1=(
from f in GRPA
group f by f.Answer into FG
select FG.Count()
)});
但它给出了我不想要的第二层,因为格式 我尝试了这个:
var Q = from x in LinqDB.PTAs
where x.PTID == int.Parse(DropDownListPeriodID.SelectedValue) &&
x.PTUser.PTUserID >= ID1 && x.PTUser.PTUserID <= ID2
group x by new { x.PTQID, x.Answer } into gr
select new {gr.Key.PTQID,gr.Key.Answer,A1=gr.Count() };
那么对此有何建议,或者可能更改后处理中的第二个查询,以便它可以像我的格式一样? 谢谢您的回答。
Hi
i want to create a query for a table that is like this:
1.i have a multiple question and i want to count the number of each response to every answer to multiplequestion result and show them in a query that is formated like this:
1.ID 2.qestion phrase 3.q1 4.q2 5.q3 6.q4 7.count1 8.count2 9.count3 10.count4
i have created a linq query like this that is from answers table and after that i can join these with the ID to questions table and get the phrase and other:
var q4 = (from x in LinqDB.PTAs
where x.PTID == int.Parse(DropDownListPeriodID.SelectedValue) &&
x.PTUser.PTUserID >= ID1 && x.PTUser.PTUserID <= ID2
group x by x.PTQID into GRPA //& x.PTAID
select new {
GRPA.Key,
A1=(
from f in GRPA
group f by f.Answer into FG
select FG.Count()
)});
but it gives a second layer that i don't want becouse of the format
i tried this:
var Q = from x in LinqDB.PTAs
where x.PTID == int.Parse(DropDownListPeriodID.SelectedValue) &&
x.PTUser.PTUserID >= ID1 && x.PTUser.PTUserID <= ID2
group x by new { x.PTQID, x.Answer } into gr
select new {gr.Key.PTQID,gr.Key.Answer,A1=gr.Count() };
so any suggestions to this or maybe changing the second query in a post processing so it can be like my format?
Thx for your Answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)