zoukankan      html  css  js  c++  java
  • sql查重去除id最小值

    select order_id
    FROM
        yzj_store_order t
    WHERE
        (t.user_id,t.order_status) IN ( SELECT user_id,order_status FROM yzj_store_order where order_status=0 AND DATE_FORMAT( create_date, '%Y-%m-%d' ) = DATE_FORMAT( CURDATE( ) - 0, '%Y-%m-%d' )  GROUP BY user_id,order_status HAVING count( * ) > 1 ) 
        AND DATE_FORMAT( create_date, '%Y-%m-%d' ) = DATE_FORMAT( CURDATE( ) - 0, '%Y-%m-%d' ) 
        AND id NOT IN (
    SELECT
        min( id ) 
    FROM
        yzj_store_order 
    WHERE
        DATE_FORMAT( create_date, '%Y-%m-%d' ) = DATE_FORMAT( CURDATE( ) - 0, '%Y-%m-%d' ) 
        and order_status=0
    GROUP BY
        user_id,order_status
    HAVING
        count( * ) > 1 
        ) ORDER BY user_id desc
        
        select order_id
    FROM
        yzj_store_order t
    WHERE
        (t.user_id,t.order_status) IN ( SELECT user_id,order_status FROM yzj_store_order where order_status=1 AND DATE_FORMAT( create_date, '%Y-%m-%d' ) = DATE_FORMAT( CURDATE( ) - 0, '%Y-%m-%d' )  GROUP BY user_id,order_status HAVING count( * ) > 1 ) 
        AND DATE_FORMAT( create_date, '%Y-%m-%d' ) = DATE_FORMAT( CURDATE( ) - 0, '%Y-%m-%d' ) 
        AND id NOT IN (
    SELECT
        min( id ) 
    FROM
        yzj_store_order 
    WHERE
        DATE_FORMAT( create_date, '%Y-%m-%d' ) = DATE_FORMAT( CURDATE( ) - 0, '%Y-%m-%d' ) 
        and order_status=1
    GROUP BY
        user_id,order_status
    HAVING
        count( * ) > 1 
        ) ORDER BY user_id desc

    sql查重重保留最小值

  • 相关阅读:
    Python 列表字典制作名册管理
    AS3获取SWF文件中AS链接
    AS3多选多模型
    AS3视频播放器
    测试
    Makefile三个有用变量$@,$^,$<
    CentOS 7.2 安装教程
    Ubuntu 查看/修改文件编码
    API 进程、线程函数
    API 菜单函数
  • 原文地址:https://www.cnblogs.com/zhangrongfei/p/11945502.html
Copyright © 2011-2022 走看看