FMDB

Useful ways to get data out of FMDB.

Count

NSUInteger count = [db intForQuery:@"SELECT COUNT(field) FROM table_name"];

Make sure to include the FMDatabaseAdditions.h header file to use intForQuery:

Max

NSUInteger max = [db intForQuery:@"SELECT MAX(field) FROM table_name"];

Min

NSUInteger min = [db intForQuery:@"SELECT MIN(field) FROM table_name"];

Average

NSUInteger average = [db intForQuery:@"SELECT AVG(field) FROM table_name"];

Sum (Σ)

NSUInteger sum = [db intForQuery:@"SELECT SUM(field) FROM table_name"];

Total

NSUInteger total = [db intForQuery:@"SELECT TOTAL(field) FROM table_name"];

https://www.sqlite.org/lang_aggfunc.html

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: