我正在制作一个小游戏,它可以获得最佳关卡和你完成的关卡数量,超过一半的问题是正确的。我有一个检查这个的查询,但我不知道如何整合问题表的问题。如果用户没有尝试回答问题,则不会在答案表中写入任何行。所以它现在实际上与每个级别的答案表中的行数进行比较。关于如何整合它的任何想法?(count(*)/2) 实际上
Cursor c = myDataBase
.rawQuery(
"select level, (select count(*) from ( select level from answers group by level having sum (answercorrect) >= (count(*)/2) ) answers ) completedlevels, "
+ "from answers "
+ "group by level "
+ "order by sum (score) desc ", null);
我试过了,但没有用:
Cursor c = myDataBase
.rawQuery(
"select level, (select count(*) from ( select level from questions group by level having sum (answercorrect) >= ((select count(*)/2 from questions group by level) ) answers ) completedlevels, "
+ "from answers "
+ "group by level "
+ "order by sum (score) desc ", null);
编辑 表结构是:
questions table
id level question
1 1 question1level1
2 1 question2level1
...
30 1 question30level1
31 2 question1level2
32 2 question2level2
...
70 2 question40level2
71
...
//注意:每个级别可以有不同数量的问题
答案表
id question_id player answercorrect score attempts
1 5 1 1 1000 1
2 10 1 1 900 1
3 7 2 0 700 3
4 10 2 0 500 3
5 13 2 1 100 1
6 8 1 1 800 2
...