我在Postgres
- testscores
和questions
中有两个表格。 Testscores
是一个表,用于存储有关某人所进行的测试的信息以及相应测试中涉及的问题。这两个表都有questionid
,我正在加入它们。
示例数据集:
Testscores
TestscoreId QuestionId Created
100 224 2014-23-08
100 986 2014-12-12
100 126 2013-1-9
101 986 2015-2-7
101 376 2013-3-6
102 264 2015-30-11
Questions
QuestionId irt_tlevel
986 easy
376 hard
264 medium
126 easy
986 medium
224 medium
我希望得到以下结果:
TestscoreId Questions Created Number Irt_tlevel
100 3 2013-1-9 1 medium
100 3 2014-23-08 2 medium
100 3 2014-12-12 3 easy
101 2 2013-3-6 1 hard
101 2 2015-2-7 2 easy
102 1 2015-30-11 1 medium
我正在尝试运行以下查询:
select a.testscoreid, count(a.*) as Questions, a.created, row_number() OVER(partition by a.created order by a.created) as Number, b.irt_tlevel
from asmt.testscores a join asmt.questions b
on a.questionid = b.questionid
where a.answered = true
group by a.testscoreid, a.created, b.irt_tlevel
order by Questions desc, a.created asc
我相信这个查询会给我我正在寻找的结果,但它需要永远计算,它甚至没有完成一次。 Testscores
有8800万行,Questions
有164k行。
有没有更好的方法来运行此查询?我可以更快地获得结果吗?已经一个小时了,我什么都没有...... 在这方面的任何帮助将受到高度赞赏。
修改
这正是我想要的:
testscoreid
对应于测试者进行的测试。对于每个testscoreid
,有多个questionid
对应于测试者在测试中回答的问题。考虑到所有testscoreid
,我想提供一份报告,告诉我以下数据:
Easy
次,Medium
次B次,Hard
次C次Easy
X次,Medium
Y次,Hard
Z次
<磷>氮。对于所有测试,发布给测试者的问题#N为
Easy
次P次,Medium
次Q次,Hard
R次
N
是最长测试中尝试的最大问题数量,例如 - 如果5个人在5个不同的测试中回答了200,100,400,350和500个问题,那么N
将是500。