SQLite C++ 比较同一数据库中的两个表以匹配记录

SQLite C++ Compare two tables within the same database for matching records

本文关键字:两个 记录 比较 C++ 数据库 SQLite      更新时间:2023-10-16

我希望能够使用C++接口来匹配记录来比较同一SQLite数据库中的两个表。这是我的两个表

表名 : 临时图

ID          TEMPTRIGRAM       
----------  ----------  
1           The cat ran        
2           Compare two tables       
3           Alex went home
4           Mark sat down      
5           this database blows
6           data with a
7           table disco ninja 
++78

表名:垃圾邮件三元组

ID          TRIGRAM       
----------  ----------  
1           Sam's nice ham        
2           Tuesday was cold       
3           Alex stood up
4           Mark passed out      
5           this database is
6           date with a
7           disco stew pot
++10000 
第一个表有两列

和 85 条记录,第二个表有两列,有 10007 条记录。

我想取第一个表并比较 TEMPTRIGRAM 列中的记录,并将其与第二个表中的 TRIGRAM 列进行比较,并返回表中的匹配数。因此,如果 (ID:1 "The Cat Ran" 出现在"spamtrigrams"中,我希望将其计数并在末尾以整数形式返回总计。

有人可以解释一下执行此操作的查询语法吗?

谢谢。

这是一个

带有aggregationjoin查询。 我的猜测是你想要每trigram的比赛次数:

select t1.temptrigram, count(t2.trigram)
from table1 t1 left outer join
     table2 t2
     on t1.temptrigram = t2.trigram
group by t1.temptrigram;

如果您只想要匹配数:

select count(t2.trigram)
from table1 t1 join
     table2 t2
     on t1.temptrigram = t2.trigram;