1

I have 2 tables one with names and id's and another with id's and dates, I am trying to figure out how to create the helper method to query the two tables and return the list of names with the number of dates associated to their id.

Name Table
   id  Name
    1 John
    2 Tom
    3 Frank

Date Table
   id  Date
    1 1/3/19
    1 1/4/19
    1 1/5/19
    2 1/4/19

    Results:
    Name  Count
    John  3
    Tom   1
    Frank 0

This is as far as I have gotten just pulling back all the names.

  Future<List> queryAllNames() async {
    Database db = await database;
    List<Map> names =
        await db.query(Names, columns: [id, Name]);
    if (names.length > 0) {
      return names;
    }
    return null;
  }

I have figured out the raw query I need from sqlite

select Name.name,  count(Date.date) from Name left join Date using(id) group by Name.name;

But still not able to translate to at sqflite helper method.

4

1 回答 1

6

There is a rawQuery() method. Check out Raw SQL queries

于 2019-05-28T21:07:37.880 回答