I want to select the distinct keys with the occurence number, this query seems functionate:
SELECT ItemMetaData.KEY, ItemMetaData.VALUE, count(*)
FROM ItemM
Here is the explanation: WHERE clause introduces a condition on individual rows; HAVING clause introduces a condition on aggregations.
Use WHERE before GROUP BY and HAVING after GROUP BY. It isn't mandatory, but helpuful in most cases.
SELECT
ItemMetaData.KEY, ItemMetaData.VALUE, СOUNT(*)
FROM ItemMetaData
GROUP BY
ItemMetaData.KEY, ItemMetaData.VALUE
HAVING СOUNT(*) > 2500
ORDER BY СOUNT(*) DESC;