Remove duplicate data by day. If the value is 0, 0 is used. Otherwise, the maximum value is used.

Source: Internet
Author: User
Test data: mysql> select * From T2; + ---- + -------- + --------------------- + ---------- + | ID | userid | inputdate | infostatus | + ---- + -------- + --------------------- + ---------- + | 1 | 1 | 00:00:00 | 20013 | 2 | 1 | 00:00:00 | 0 | 3 | 2 | 00:00:11 | 20015 | 4 | 2 | 00:00:22 | 20013 | 5 | 2 | 00:00:00 | 0 | 6 | 2 | 00:00:00 | 20013 | 7 | 2 | 00:00:00 | 0 | 8 | 2 | 00:00:00 | 0 | 9 | 2 | 00:00:00 | 20013 | 10 | 2 | 00:00:00 | 0 | 11 | 2 | 00:00:00 | 0 | + ---- + -------- + ----------------------- + ------------ + query SQL: select ID, userid, date (inputdate) as date, max (infostatus) as M, min (infostatus) As I, if (min (infostatus) = 0, max (infostatus )) as Max from T2 where infostatus = 0 or infostatus <= 99999 group by date; receipt result: + ---- + -------- + ------------ + ------- + | ID | userid | date | M | I | max | + ---- + -------- + ------------ + ------- + | 1 | 1 | 2014-07-11 | 20013 | 0 | 0 | 3 | 2 | 2014-07-12 | 20015 | 20013 | 20015 | 9 | 2 | 20013 | 0 | 0 | 5 | 2 | 2014-07-14 | 0 | 0 | 0 | 6 | 2 | 2014-07-15 | 20013 | 0 | 0 | 8 | 2 | 2014-07-16 | 0 | 0 | 0 | + ---- + -------- + ------------ + ------- + my idea is to group by time, at the same time, the query is the smallest, followed by the largest. If the smallest is 0, then the max field is 0; otherwise, the largest one is obtained.

 

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.