sql查询(两个表之间的输出结果不一样)

时间:2014-02-14 04:47:13

标签: sql

我有2个表TableATableB,其属性为id, character

TableA
╔════╦═══════════╗
║ id ║ character ║
╠════╬═══════════╣
║  1 ║     A     ║
║  2 ║     B     ║
║  3 ║     C     ║
╚════╩═══════════╝

TableB
╔════╦═══════════╗
║ id ║ character ║
╠════╬═══════════╣
║  1 ║     A     ║
║  2 ║     B     ║
║  3 ║     D     ║
╚════╩═══════════╝

我想计算TableATableB之间字符列中有多少字符不匹配。

我不确定这是否正确:

SELECT COUNT(character) 
FROM TableA tba 
JOIN TableB tbb 
   ON tba.id = tbb.id 
WHERE tba.character NOT LIKE tbb.character 
GROUP BY character

1 个答案:

答案 0 :(得分:0)

您不需要group by语句:

SELECT COUNT(*)   
FROM TableA tba 
INNER JOIN TableB tbb 
   ON tba.id = tbb.id 
WHERE tba.character <> tbb.character