2
我有一個MySQL表與下面的模式:MySQL查詢,爲值時出現不止一次對同一個客戶端
表 - charges
+=============+==============+
| chargeName | clientId |
+=============+==============+
| late fee | 123456 |
+-------------+--------------+
| late fee | 123456 |
+-------------+--------------+
| payment | 123456 |
+-------------+--------------+
| refund | 782151 |
+-------------+--------------+
| late fee | 782151 |
+-------------+--------------+
我需要返回的實例,其中chargeName
「滯納金「出現在同一clientId
不止一次。
例如,鑑於上述情況,我期望我的查詢返回「123456」,因爲該clientId
有2個與其關聯的「滯納金」。
我試圖從SQL Query To Obtain Value that Occurs more than once
SELECT clientId
FROM
(SELECT chargeName, count(*) as Counter, clientId
FROM charges
GROUP BY `chargeName`)
AS tbl
WHERE Counter > 1
AND chargeName='late fee'
limit 1000;
但是適應this answer,此查詢只返回一行(從我更大的數據集),並返回ClientID的只有它這麼清楚它是有關1個滯納金不工作。
如何才能返回chargeName
「滯納金」出現在同一clientId
多次的情況。
這是一個由'having' count> 1組 – Drew