iOS Swift: How to perform SQL SUM() function using MSQuery and NSPredicate?

|▌冷眼眸甩不掉的悲伤 提交于 2020-06-29 03:49:16

问题


For example, I would like something similar to:

select SUM[likes] from [MyAzureSQLService].[InstagramPost] where user == 'rain'

Here, the "likes" is unsigned integer column in azure sql table "[MyAzureSQLService].[InstagramPost]", I wanted to query the sum number of all likes received by a specific user.

My Swift code in iOS is like this:

guard let table = client.table(withName: tableName) else { return }
guard let query = MSQuery(table: table) else { return }
query.predicate = NSPredicate(format: "user == 'rain'")
query.selectFields = ["SUM(likes)"]

But this didn't work, any ideas?

Thanks!

来源:https://stackoverflow.com/questions/62380694/ios-swift-how-to-perform-sql-sum-function-using-msquery-and-nspredicate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!