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

(SELECT COUNT(*) FROM Vocab) - (SELECT COUNT(*) FROM Vocab GROUP BY Word)
但是它返回了一个错误Unexpected token. (near "-" at position 29),我如何实现我的目标?

最佳答案

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

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

关于mysql - 查找两个不同查询的总数之间的差异SQL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43641768/

10-16 04:48