第一个,3月1号之前注册的,并且4月1号之前没有订单的用户数select *
from user u
where registered_time<3月1号
and not exists (select 1 from `order` where user_id=u.id and order_time<4月1号);

解决方案 »

  1.   

    第二个,3月1号之前注册的,并且4月1号之前没有订单的,4月1号到4月30又有订单的
    from user u
    where registered_time<3月1号
    and not exists (select 1 from `order` where user_id=u.id and order_time<4月1号)
    and exists (select 1 from `order` where user_id=u.id and order_time between 4月1号 and 4月30)
      

  2.   

    3月1日之前注册,4月1日前有过1到3个订单,并且在大多数订单在2月1日和3月31日之间。请问大多数,这种怎么写sql
      

  3.   

    当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
    http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
    http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html8、如何给分和结贴?
    http://community.csdn.net/Help/HelpCenter.htm#结帖