找出两个不同查询SQL总数之间的差异

时间:2017-04-26 18:21:25

标签: mysql sql

我有一个表Vocab,我想找到总行数和重复数,这是我试过的代码

(SELECT COUNT(*) FROM Vocab) - (SELECT COUNT(*) FROM Vocab GROUP BY Word) 但它给我一个错误Unexpected token. (near "-" at position 29),我怎样才能实现我的目标?

1 个答案:

答案 0 :(得分:3)

我认为你想要count(distinct)和一些算术:

select count(*) as total_words,
       count(distinct word) as total_distinct_words,
       (count(*) - count(distinct word)) as must_be_duplicated
from Vocab;