SQLite select 并从另一个 table 开始计数

SQLite select and count from another table with like

我有如下两个表:

TABLE 人

           ------------------------------
           idpers | name      | firstname
           ------------------------------
           1      | John      | Miad
           2      | Eddy      | Rowan
           3      | Phil      | Barzoon
           ...

TABLE 任务

           -----------------------------------------------------------------------
           id_td  |  date     | task           | protocol
           -----------------------------------------------------------------------
           211    | 13-12-19  | Mount          | 13-12-19•John Miad→13-12-19•Eddy Rowan
           348    | 14-12-19  | Fix and clean  | 14-12-19•Eddy Rowan
           256    | 15-12-19  | Lubricate      | 15-12-19•Phil Barzoon
           265    | 15-12-19  | First run      | 15-12-19•Phil Barzoon→15-12-19•John Miad
           ...

我想创建一个视图 DAILY_TOTAL_BY_DOER 计算每个名称完成的任务数量

查看示例:

enter code here
           ------------------------------------------------------------------------
              date  | idpers    | name      | firstname | total_tasks 
           ------------------------------------------------------------------------
           13-12-19 | 1         | John      | Miad      |  7    
           13-12-19 | 2         | Eddy      | Rowan     |  3    
           13-12-19 | 3         | Phil      | Barzoon   |  8    
           14-12-19 | 6         | Andreas   | werner    |  5   
           ...

非常感谢您的帮助。

如果列 protocol 的格式始终与示例数据中的格式相同,那么您可以加入表格并按日期和人员分组:

select t.date, p.idpers, p.name, p.firstname, count(*) total_tasks 
from persons p inner join tasks t
on t.protocol  || '→' like '%•' || p.name || ' ' || p.firstname || '→%'
group by t.date, p.idpers, p.name, p.firstname

参见demo