MySQL complex query statement, work in the record under

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.