i'm new to Mysql and SO,let me know if my question is not clear
我是Mysql和SO的新手,如果我的问题不清楚,请告诉我
i have a table like this
我有一张这样的桌子
key | value
-----------------------
key1 | value3
key1 | value3
key1 | value1
key3 | value4
key3 | value2
key4 | value1
key4 | value1
key5 | value2
i need count of each distinct value that matched with unique keys.
我需要计算与唯一键匹配的每个不同值。
For EX: i need o/p like
对于EX:我需要o / p之类的
(
(key1,value1:1,value3:2),
(key3,value2:1,value4:1),
(key4,value1:2),
(key5,value2:1,)
)
can anyone suggest me the query.
任何人都可以建议我查询。
Edit: I used group by
like
编辑:我喜欢分组
select value, count(*) from table GROUP BY value;
but it's not giving proper results.
但它没有给出正确的结果。
1 个解决方案
#1
-1
I just tested this query with the same table you gave and it gave the results you are asking for
我刚用你给的同一个表测试了这个查询,它给出了你要求的结果
SELECT key, value, COUNT(*)
FROM your_table
GROUP BY
key, value
HAVING
COUNT(*) >= 1
ORDER BY key
#1
-1
I just tested this query with the same table you gave and it gave the results you are asking for
我刚用你给的同一个表测试了这个查询,它给出了你要求的结果
SELECT key, value, COUNT(*)
FROM your_table
GROUP BY
key, value
HAVING
COUNT(*) >= 1
ORDER BY key