繁体   English   中英

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

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

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

表名:temptrigrams

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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM