如何从我的sqlite中获取列的平均值形式?

时间:2014-07-03 07:04:42

标签: sql sqlite android-sqlite average

您好我正在使用sqlite。当我在数据中查找未赋值的平均值时,我已经在sqlite中存储了一些字段。

cursor = database.rawQuery("Select '"+start+"' as dateadded ,AVG('ch4') as 'ch4',AVG('c2h2') as 'c2h2',AVG('c2h4') as 'c2h4' where dateAdded between '"+start+"' and '"+end+"' and '"+edd+"' = '"+equipid+"' ",null);

我这样写的是返回值,但这不正确。我认为问题是我没有写任何表名。

当我在sqlite中执行只返回dateadded并且remaning all的代码为空时。

Select '02-07-14 11:58' as dateadded ,AVG('ch4') as ch4,AVG('c2h2') as c2h2,AVG('c2h4') as c2h4 where dateAdded between '02-07-14 11:58' and '03-07-14 11:58' and "equipid" = '2'

如果我写代码

Select '02-07-14 11:58' as dateadded ,AVG('ch4') as ch4,AVG('c2h2') as c2h2,AVG('c2h4') as c2h4 where dateAdded between '02-07-14 11:58' and '03-07-14 11:58' and "equipid" = '2' FROM dgadata

dgadata是表名。但那显示出类似的内容

Error:near "FROM": syntax error: 

那么请你告诉我如何在android sqlite中编写平均值的查询。

谢谢

香卡

2 个答案:

答案 0 :(得分:2)

你的语法错误。 你用

SELECT ... WHERE ...FROM...

正确

SELECT .... FROM ... WHERE ...

答案 1 :(得分:0)

选择' 02-07-14 11:58'作为日期添加,AVG(' ch4')为ch4,AVG(' c2h2')为c2h2,AVG(' c2h4')为c2h4,其中date添加在&#39之间; 02-07-14 11:58'和' 03-07-14 11:58'和" equipid" =' 2'

在此查询中请在tablename之前添加

选择' 02-07-14 11:58'作为datename从tablename添加日期在' 02-07-14 11:58'之间和' 03-07-14 11:58'和" equipid" =' 2'