如何从2的计数中减去mysql查询的结果

时间:2018-01-10 18:50:00

标签: mysql

我是mysql的新手。我有2个单独的查询,这些查询给了我数量。

我想得到[COUNT 1 - COUNT 2]。但是,我不知道如何在mysql中做到这一点。

以下是我的查询

(select COUNT(CITY) as M from STATION) 
MINUS
(select COUNT(DISTINCT CITY) as N from STATION) 

错误

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-
(select COUNT(DISTINCT CITY) as N from STATION)' at line 2

3 个答案:

答案 0 :(得分:1)

您可以在单个查询中执行此操作,例如

SELECT COUNT(CITY) - COUNT(DISTINCT CITY)
FROM STATION

答案 1 :(得分:0)

解决

选择 ((从STATION选择COUNT(CITY)为M) 减去 (选择COUNT(DISTINCT CITY)作为ST的N))作为计数 来自STATION LIMIT 1

答案 2 :(得分:0)

尝试此查询!

选择               COUNT(CITY)
                -               COUNT(DISTINCT CITY) 如              ' M-N' 从              STATION