从计算检索到的行搜索SQLite数据库和使用价值 [英] Search SQLite Database and use values from retrieved rows for calculation
问题描述
我试图寻找这一点,但也许我错误地寻找它。
I tried to search for this but maybe I'm looking for it incorrectly.
这是一个Android应用程序。
从本质上讲,我想基于一些条件来搜索数据库(例如,子类别和项目名称),然后使用一些其他的数据值的行做的计算中(如得到的价格值,并使用它来计算)
This is for an android app. Essentially, I want to search the database based on some criteria (e.g. subcategory and item name), then use some of the other data values in the row to do a calculation (e.g. get the price value, and use it for a calculation)
我想是这样的查询。
Cursor d = db.rawQuery("SELECT * FROM prices WHERE subcat = 'meat' AND item = 'lamb' ")
现在我需要获取列(如价格),并使用值来计算类似均价..我会怎么做呢? (假设第1步是正确的)...
Now I would need to retrieve a column (like price) and use the values to calculate something like the average price.. How would I do that? (assuming step 1 is correct)...
推荐答案
您可以使用聚合函数基于多个记录中列的值来计算单个值:
You can use aggregate functions to compute a single value based on a column's value in multiple records:
SELECT AVG(price) FROM prices WHERE subcat = 'meat' AND item = 'lamb'
这篇关于从计算检索到的行搜索SQLite数据库和使用价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!