报错解决:DB::Exception: Scalar subquery returned more than one row.

it2022-05-05  251

在使用clickhouse的时候报错了:

Received exception from server (version 19.5.3): Code: 125. DB::Exception: Received from localhost:9000, 127.0.0.1. DB::Exception: Scalar subquery returned more than one row.

我的查询语句如下:

SELECT count(*) FROM test.app_pv_13 WHERE appid = ( SELECT DISTINCT appid FROM test.app_pv_13 );

我也这个查询语句的目的是为了查询每个appid的个数,但是出错了,因为 where语句中的判断的右边返回了不止一个返回值。 如果我想要统计每个appid的个数,做法很简单:

SELECT appid, count(*) FROM test.app_pv_13 GROUP BY appid

使用GROUP BY语句,自动帮你按appid进行分类,然后统计个数就可以了。 参考:SQL Server query - Selecting COUNT(*) with DISTINCT - Stack Overflow


最新回复(0)