String shenglv2="select user_name,sum(user_amount)/sum(amount) * 100 as rate,count(user_amount)/count(amount) as rate2 from bets where user_amount>0 group by user_name

解决方案 »

  1.   

    select user_name,sum(user_amount)/sum(amount) * 100 as rate,count(user_amount)/count(amount) as rate2 
    from bets
    where user_amount>0 
    group by user_name
      

  2.   

    <% String shenglv2="select user_name,sum(user_amount)/sum(amount) * 100 as rate,count(user_amount)/count(amount) as rate2 from bets where user_amount>0 group by user_name";%>
      

  3.   

    String shenglv2="select user_name,sum(user_amount)/sum(amount) * 100 as rate,count(user_amount)/count(amount) as rate2 from bets where user_amount>0 group by user_name
      

  4.   

    String shenglv2="select user_name,sum(user_amount)/sum(amount) * 100 as rate,count(user_amount)/count(amount) as rate2 from bets where user_amount>0 group by user_name
      

  5.   

    String shenglv2="select user_name,sum(user_amount)/sum(amount) * 100 as rate,count(user_amount)/count(amount) as rate2 from bets where user_amount>0 group by user_name
      

  6.   

    user_amount会小于0吗,不会的话,统计一下也没关系,除非0的那种记录你最终不要
      

  7.   

    我也这样加过,但是这样统计的是count(user_amount)/count(amount)在user_amount>0的所有用户count(user_amount)/count(user_amount),我的意思是统计count(user_amount)的条件是user_amount>0,
    而不是count(user_amount)/count(amount)只统计user_amount>0.
      

  8.   

    不知你用的是什么数据库系统,sql语句可以这样写:
    select a.user_name,
      sum(a.user_amount)/sum(amount) * 100 as rate,
      sum(count_gt0)/sum(count_all) * 100 as rate2
    from (
    select user_name,
      0 as user_amount, 0 as amount, 
      count(user_amount) as count_gt0, 0 as count_all
    from bets where user_amount > 0 group by user_name
    union all
    select user_name,
      sum(user_amount) as user_amount, sum(amount) as amount,
      0 as count_gt_0, count(user_amount) as count_all
    from bets group by user_name) a
    group by a.user_name
      

  9.   

    以上有误,修正如下:
    select a.user_name,
      sum(a.user_amount)/sum(a.amount) * 100 as rate,
      sum(a.count_gt0)/sum(a.count_all) * 100 as rate2
    from (
    select user_name,
      0 as user_amount, 0 as amount, 
      count(user_amount) as count_gt0, 0 as count_all
    from bets where user_amount > 0 group by user_name
    union all
    select user_name,
      sum(user_amount) as user_amount, sum(amount) as amount,
      0 as count_gt0, count(user_amount) as count_all
    from bets group by user_name) a
    group by a.user_name
      

  10.   

    老大 不是你走错门了
    就是我看花眼了
    这里好象是Java版吧?