Home > database >  Mysql in the group by later want to get to the second record in a group?
Mysql in the group by later want to get to the second record in a group?

Time:10-01

Mysql in the group by later want to get to the second record in a group?

Pictured above, how to use mysql to achieve?

CodePudding user response:

Write a second element aggregation function, hypothesis is secitem
Select * from table where signtime in (select secitem (signtime) from table group by name)

CodePudding user response:

Just that kind of method is a little problem, another method:
Select * from table a where 1=(Select count (*) from the table where a.n ame=name and a.t ime & gt; Time)

CodePudding user response:

Remove the smallest one in each group, each group from the rest of the data the smallest can just have a
 SELECT * FROM TB 
WHERE baoxian_id IN (
The SELECT min (baoxian_id) FROM TB
WHERE baoxian_id NOT IN (
The SELECT min (baoxian_id) FROM TB GROUP BY name)
GROUP BY name)
The ORDER BY name.

CodePudding user response:

reference ZJCXC reply: 3/f
remove each set of the smallest one, from the rest of the data of each set of the smallest can just have a
 SELECT * FROM TB 
WHERE baoxian_id IN (
The SELECT min (baoxian_id) FROM TB
WHERE baoxian_id NOT IN (
The SELECT min (baoxian_id) FROM TB GROUP BY name)
GROUP BY name)
The ORDER BY name.

That if these records each group after group has N, I want to take each group of the first N/2 digits?

CodePudding user response:

 select * from (select id, name, @ id:=the if (@ name=name, @ id + 1, 0) as _r, @ name:=name as _n from TB, (select @ id:=0, @ name:=null) b order by name) aa where _r % 2; 
  • Related