1 go to re-query
Select DISTINCT ID from User_info where xxxxxx
2 sorting in GROUP by grouping queries
The group by itself does not have a sort function, which is probably not the perfect place for MySQL, but we can do that
Select attack_id, Time from (SELECT * from Attack_log where (time+172800) < Unix_timestamp (now ()) Order by time Desc) a Ttack_log GROUP BY attack_id
* Note: first by sorting rows into a set, and then to change the collection to check, so that the grouping to achieve a sort of query
3 Finding the top two data that meets your requirements
Select Attack_id,time from Attack_log a where (select count (*) from attack_log where attack_id = a.attack_id and Time > A.time) <2
* Note: Where the back is actually a bool value. Filter compliant data with BOOL values
MySQL database migration (two songs)
1 mysqldump-uroot-p scbdb >>/home/zhangchuan/scbdb.sql (Generate SQL file for database to be migrated)
2 in MySQL environment source./scbdb.sql; (executes the statement in the MySQL environment of the target database)
It's so simple.
MySQL complex query statement, work in the record under