[英]group every 3 count rows with mysql query
can anyone help me to group every 3 counts rows???谁能帮我把每 3 个计数行分组??? I have data like this我有这样的数据
num数 | score分数 |
---|---|
1 1 | 3 3 |
1 1 | 3 3 |
1 1 | 3 3 |
1 1 | 3 3 |
1 1 | 3 3 |
1 1 | 3 3 |
4 4 | 3 3 |
4 4 | 3 3 |
4 4 | 3 3 |
2 2 | 3 3 |
2 2 | 3 3 |
2 2 | 3 3 |
and i want result like this我想要这样的结果
num数 | count(num)计数(数量) |
---|---|
1 1 | 3 3 |
1 1 | 3 3 |
2 2 | 3 3 |
4 4 | 3 3 |
Please read terms & condition for asking in Stackoverflow.请阅读在 Stackoverflow 中询问的条款和条件。 Your question can't be understood!你的问题无法理解!
You want to group every 3 rows.您想每 3 行分组一次。 But without giving supplementary conditions, we can only take assumptions on how you would like to group.但在不提供补充条件的情况下,我们只能假设您希望如何分组。 Supposing each row in the 3-rows group has the same content and the score value from the base table has no influence on grouping, I guess you just want to get the num once for every 3 rows as the 3 rows have the same num.假设 3 行组中的每一行具有相同的内容,并且基表中的分值对分组没有影响,我猜你只想每 3 行获取一次 num,因为 3 行具有相同的 num。 Besides, we use a constant value 3
for count(num)
column.此外,我们对count(num)
列使用常量值3
。 If all my assumptions come true, try this:如果我所有的假设都成真,试试这个:
select num, 3 as 'count(num)'
from (select num,@row_id:=@row_id+1 as row_id
from test,(select @row_id:=0) t1 ) t2
where row_id mod 3 =0
order by num
;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.