0

次のようなsqliteテーブルにデータがあります

これが私のテーブルの説明とフィールドです

    coffeeID;
category;
sub_Category;
content_Type;
content_Title;
content_Description;
content_Id;
publisher;
content_Source;
update_date_time;

ここに、すべての値を取得しているコードがありますが、一意の値が必要です。

       const char *sql = "select * from category";


    sqlite3_stmt *selectstmt;
    if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {

        while(sqlite3_step(selectstmt) == SQLITE_ROW) {

            NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
            Coffee *coffeeObj = [[Coffee alloc] initWithPrimaryKey:primaryKey];
            coffeeObj.category=sqlite3_column_int(selectstmt,1);
            coffeeObj.sub_Category = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)];
            coffeeObj.content_Type = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)];
            coffeeObj.content_Title = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,4)];

            coffeeObj.publisher = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 5)];
            coffeeObj.content_Description = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 6)];
            coffeeObj.content_Id = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 7)];
            coffeeObj.content_Source = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 8)];

            int count=[appDelegate.coffeeArray count];

            NSLog(@"count is beofore getting values %d",count);



            [appDelegate.coffeeArray addObject:coffeeObj];



            int countone=[appDelegate.coffeeArray count];

            NSLog(@"count is after getting values %d",countone);

            [coffeeObj release];
        }
    }
}

同じサブカテゴリが2つある場合、同じ名前のカテゴリが繰り返されるのではなく、一意のレコードのみを意味するように、1つだけが表示される可能性があります。

4

1 に答える 1

0

SQLクエリでGroup byを使用できます

"Select * From category GROUP BY category"

任意の列でグループ化できます

于 2013-04-16T10:31:35.430 に答える