SQL 使用 group_concat 每个串联项目的计数而不是一行中的总计数
SQL using group_concat with count of each concatenated item rather total count in a row
我改写成this fiddle,但是报错
有人可以帮忙吗?
就此而言,要解决错误并获得正确的结果,您只需要 return 来自聚合子查询的 CUSTOMERID
(该列已经是 [=13 的一部分=] 子句).
更新查询:
SELECT SELLER,
COUNT(*) as COUNT_OF_CUSTIDS,
GROUP_CONCAT(CUSTOMERID, ' (', cnt, ')' SEPARATOR '|') AS CUSTIDS
FROM (
SELECT SELLER, CUSTOMERID, COUNT(*) as cnt
FROM docs
GROUP BY SELLER, CUSTOMERID
) t
GROUP BY SELLER
HAVING COUNT(*) > 1
Returns:
| SELLER | COUNT_OF_CUSTIDS | CUSTIDS |
| ------ | ---------------- | -------------------- |
| S1 | 3 | C2 (2)|C1 (2)|C3 (3) |
| S2 | 3 | C3 (1)|C2 (1)|C1 (2) |
我改写成this fiddle,但是报错
有人可以帮忙吗?
就此而言,要解决错误并获得正确的结果,您只需要 return 来自聚合子查询的 CUSTOMERID
(该列已经是 [=13 的一部分=] 子句).
更新查询:
SELECT SELLER,
COUNT(*) as COUNT_OF_CUSTIDS,
GROUP_CONCAT(CUSTOMERID, ' (', cnt, ')' SEPARATOR '|') AS CUSTIDS
FROM (
SELECT SELLER, CUSTOMERID, COUNT(*) as cnt
FROM docs
GROUP BY SELLER, CUSTOMERID
) t
GROUP BY SELLER
HAVING COUNT(*) > 1
Returns:
| SELLER | COUNT_OF_CUSTIDS | CUSTIDS |
| ------ | ---------------- | -------------------- |
| S1 | 3 | C2 (2)|C1 (2)|C3 (3) |
| S2 | 3 | C3 (1)|C2 (1)|C1 (2) |