...
Panel |
---|
mysql> select *, count(*) as count from table-name group by field1, field2, ... having count(*) >1; |
...
Get median generally
...
There are some useful group by functions in MySQL, like avg(), std(), max() and so on, but there is not a median function. Following SQL statement is a general way to achieve this purpose
No Format |
---|
SELECT m.name, avg(m.medians) medians from (
SELECT x.name, x.val medians
FROM A x, A y
WHERE x.name=y.name
GROUP BY x.name, x.val
HAVING SUM(y.val <= x.val) >= COUNT(*)/2
AND SUM(y.val >= x.val) >= COUNT(*)/2
)AS m group by m.name;
|