0

Hi I am working with sqlite. I alredy stored some fields in sqlite when i retrving the data the average values not assigned the values.

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);

I wrote like this it is return the value but that is not correct. I think the problem is i am not wrote any table name.

When i executing the code in the sqlite that is return only dateadded and remaning all are null.

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'

If i write the code like

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

The dgadata is the table name. But that is showing the like

Error:near "FROM": syntax error: 

So can you please tell me how can i write the query for average of values in android sqlite.

Thank You

Shankar

1
  • are you sure you have these columns: ch4 c2h2...? Commented Jul 3, 2014 at 7:08

2 Answers 2

2

You have a wron syntax. You use

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

Correct is

SELECT .... FROM ... WHERE ...
Sign up to request clarification or add additional context in comments.

7 Comments

drive.google.com/file/d/0B_c-SDSO63obT1hvdGNfc2xCQVU/… Select '02-07-14 11:58' as dateadded ,AVG('ch4') as ch4,AVG('c2h2') as c2h2,AVG('c2h4') as c2h4 FROM dgadata where dateAdded between '02-07-14 11:58' and '03-07-14 11:58' and "equipid" = '2' But i got all 0.0s
@user3783376 is ch4 a string or a numerical value in you DB?
That is interger: "+H2+" integer,"+CH4+" integer,"+C2H2+" integer,"+C2H4+" integer,"+
@user3783376 and these values are all not null?
Ok thanks The query is like this: Select '02-07-14 11:58' as dateadded ,AVG(ch4) as ch4,AVG(c2h2) as c2h2,AVG(c2h4) as c2h4 FROM dgadata where "equipid" = '2' ........ Before that i putted AVG('c2h4') that is not accepted.
|
0

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'

in this query please add from tablename before where

ex

select '02-07-14 11:58' as dateadded from tablename where dateAdded between '02-07-14 11:58' and '03-07-14 11:58' and "equipid" = '2'

1 Comment

Select '02-07-14 11:58' as dateadded ,AVG('ch4') as ch4,AVG('c2h2') as c2h2,AVG('c2h4') as c2h4 FROM dgadata where dateAdded between '02-07-14 11:58' and '03-07-14 11:58' and "equipid" = '2' i wrote but when i select all the values get 0.0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.