Android:获取列中的最高价值

时间:2021-02-14 13:13:24

I have an URL pointing to content and I need to get highest value contained in one of the columns. Is there any aggregate function that will accomplish that or do I have to do this manually?

我有一个指向内容的URL,我需要获得其中一列中包含的最高值。是否有任何聚合函数可以实现,或者我必须手动执行此操作?

2 个解决方案

#1


19  

If you're querying an Android content provider, you should be able to achieve this by passing MAX(COLUMN_NAME) in to the selection parameter of ContentResolver.query:

如果您要查询Android内容提供商,则应该可以通过将MAX(COLUMN_NAME)传递到ContentResolver.query的选择参数来实现此目的:

getContentResolver().query(uri, projection, "MAX(COLUMN_NAME)", null, sortOrder);

Where Uri is the address of the content provider. This should return the single row with the highest value in COLUMN_NAME.

其中Uri是内容提供商的地址。这应该返回COLUMN_NAME中具有最高值的单行。

#2


1  

Android's database uses SQLite, so SELECT MAX(thecolumn) FROM TheTable should work, just like in any other SQLite implementation (or for that matter any other SQL, "ite" or not;-). (If you're not using android.database you'd better specify what you're using instead;-).

Android的数据库使用SQLite,因此SELECT MAX(列)FROM TheTable应该可以工作,就像在任何其他SQLite实现中一样(或者就任何其他SQL而言,“ite”或不是;-)。 (如果你没有使用android.database,你最好指定你正在使用的东西;-)。

#1


19  

If you're querying an Android content provider, you should be able to achieve this by passing MAX(COLUMN_NAME) in to the selection parameter of ContentResolver.query:

如果您要查询Android内容提供商,则应该可以通过将MAX(COLUMN_NAME)传递到ContentResolver.query的选择参数来实现此目的:

getContentResolver().query(uri, projection, "MAX(COLUMN_NAME)", null, sortOrder);

Where Uri is the address of the content provider. This should return the single row with the highest value in COLUMN_NAME.

其中Uri是内容提供商的地址。这应该返回COLUMN_NAME中具有最高值的单行。

#2


1  

Android's database uses SQLite, so SELECT MAX(thecolumn) FROM TheTable should work, just like in any other SQLite implementation (or for that matter any other SQL, "ite" or not;-). (If you're not using android.database you'd better specify what you're using instead;-).

Android的数据库使用SQLite,因此SELECT MAX(列)FROM TheTable应该可以工作,就像在任何其他SQLite实现中一样(或者就任何其他SQL而言,“ite”或不是;-)。 (如果你没有使用android.database,你最好指定你正在使用的东西;-)。