我正在构建一个小游戏,它可以获得最佳级别以及您完成的级别数量,这比正确答案的一半还多。我有一个查询,检查这一点,但问题我不知道如何整合问题表。如果用户没有尝试回答问题,则不会将任何行写入答案表。所以现在它实际上与每个级别的答案表中的行数相比较。关于如何整合这个的任何想法?该(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
...
界定 “不工作” – njzk2
这是错误:11-21 18:05:40.858:E/AndroidRuntime(22175):JAVA。 lang.RuntimeException:无法启动活动ComponentInfo {com.test.com/com.Score}:android.database.sqlite.SQLiteException:near“answers”:语法错误:,在编译时:select level,(select count(*) (从答案中选择级别)(总分(答案)> =((选择数量(*)/ 2,其中答案为答案))答案)已完成级别,从答案逐级求和(分数)desc –
那'')答案)completedlevels'对我来说看起来很奇怪 – njzk2