计算特定列的类似行 [英] count similar rows of particular column

查看:70
本文介绍了计算特定列的类似行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我写了一个My SQL查询,涉及加入另一个表并按类型和uid完成,结果如下所示 -

Hi,

I have written a My SQL query that involves joining of another table and have done group by type and uid and result is something like shown below -

Type    UID     Count
MQ	37061	2
MQ	37083	1
MQ	45914	6
MQ	46520	1
MQ	47958	1
MQ	48189	1
MQ	49731	3
MQ	59893	3
MQ	68806	1
MQ	71396	1
MQ	73186	1
MQ	73770	1
NS	1057	1
NS	10717	2
NS	16310	1
NS	16512	1
NS	31885	2
NS	39441	2
NS	40578	3
NS	46166	3
NS	68353	1
NS	71169	2
NS	72483	1



结果 - 类型, uid和该类型显示相同用户ID的次数。



现在,我想知道相同类型出现的次数。有数千行。

换句话说,在上面的结果中,我想要计算列表中MQ和NS的总数。



任何想法如何实现那个?



非常感谢


it results - type, uid and number of times same user id appears for that type.

Now, I want to know the number of times same type appears. There are thousands of rows.
In other words, in above result I want to count total number of MQ and NS in the list.

Any idea how to achieve that?

Thanks a lot

推荐答案

你可以简单地使用嵌套查询。让我们假设你的内部查询是你到目前为止所做的,它返回 type uid count 字段。

You can simply use nested query. Let's assume your inner query is what you have made so far, and it is returning type, uid and count fields.
select type, count(*) from 
(/*...your inner query comes here...*/) 
group by type



或者,如果要汇总计算值,请使用:


Or, if you want to summarize the counted values, use:

select type, sum("count") from 
(/*...your inner query comes here...*/) 
group by type


这篇关于计算特定列的类似行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆