我现在有个记录用户消费的表 log_id(记录) user_id(用户id)  money(金额)  type(类型支出或收入1支出2收入)  add_time(时间)
我现在,就是要排列出, 一周内消费金额做多的5个用户,并显示消费的金额,哪位大哥指点下

解决方案 »

  1.   

    select *
    from (
    select user_id,sum(money) as sum_money
    from 记录用户消费的表
    where `type`=1
    and `add_time`>=date_add(curdate(),interval -7 day)
    group by user_id
    ) t
    order by sum_money desc 
    limit 5
      

  2.   

    add_time`>=date_add(curdate(),interval -7 day)
    距今天前七天之内
      

  3.   

    select user_id,sum(money) as total_money from 用户消费的表 where type=1 and date(add_time)>date(now()+interval -7 day) group by user_id order by total_money desc limit 5