首页 > 数据库 > mysql教程 > 按天去除重复数据,为0则取0,否则取最大的那个值_MySQL

按天去除重复数据,为0则取0,否则取最大的那个值_MySQL

WBOY
发布: 2016-06-01 13:07:08
原创
1063 人浏览过
测试数据:mysql> select * from t2;+----+--------+---------------------+------------+| id | userid | inputDate           | infoStatus |+----+--------+---------------------+------------+|  1 |      1 | 2014-07-11 00:00:00 |      20013 | |  2 |      1 | 2014-07-11 00:00:00 |          0 | |  3 |      2 | 2014-07-12 00:00:11 |      20015 | |  4 |      2 | 2014-07-12 00:00:22 |      20013 | |  5 |      2 | 2014-07-14 00:00:00 |          0 | |  6 |      2 | 2014-07-15 00:00:00 |      20013 | |  7 |      2 | 2014-07-15 00:00:00 |          0 | |  8 |      2 | 2014-07-16 00:00:00 |          0 | |  9 |      2 | 2014-07-13 00:00:00 |      20013 | | 10 |      2 | 2014-07-13 00:00:00 |          0 | | 11 |      2 | 2014-07-14 00:00:00 |          0 | +----+--------+---------------------+------------+查询sql:select id,userid,date(inputDate) as date,max(infoStatus) as m,min(infoStatus) as i,if(min(infoStatus)=0,0,max(infoStatus)) as max from t2 where infoStatus = 0 or infoStatus <p> </p>
    
登录后复制
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板