Go MySQL to group data after the time to remove the most recent data

Source: Internet
Author: User
Tags mysql view

Title, I have also found the relevant solutions on the Internet, many of the answers are such an SQL statement:
Select Id,accountid,mark,max (createtime) as Latest from Accountmark as B group by AccountId

Use the Max function. But there seems to be something wrong with the data I've looked up, and the anti-white piece of data doesn't correspond to the Mark field and the Createtime field at all!



What's going on? Does using the Max function work in groups like this?

There is also a statement: Select *,count (AccountId) as Num from
(SELECT * from Accountmark ORDER BY createtime desc) ' Temp '
Group BY AccountId ORDER BY createtime Desc
That's the right data to be found.


However, I need to create a view where query clauses are not allowed in MySQL view. Ask the big God for a SQL statement that can be implemented without clauses, and can detect the correct data. Thank you!

Workaround :

SELECT * from Accountmark as B where not exists (select 1 from Accountmark where accountid= B.accountid
and B.createtime<createtime)

Original address: http://bbs.csdn.net/topics/390958705

Go MySQL to group data after the time to remove the most recent data

Related Article

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.