噢,还要加一句,这3句能用一个SQL写出来吗?
fromtime是时间,fee是收益,spcode是代码编号.
我想实现的功能是:
按时间分组查询收益,编号为125的收益乘以0.8,编号为103的收益乘以0.6,同时能统计出这两个编号的总收益.group by这个条件中不用spcode这个字段可以?
select fromtime,count(*),fee*0.8/100 from table where spcode="125" group by fromtime,spcode,feeselect fromtime,count(*),fee*0.6/100 from table where spcode="103" group by fromtime,spcode,feeselect fromtime,count(*),fee/100 from table group by fromtime,fee

解决方案 »

  1.   

    sum(feecode*if(spcode='125',0.8, if(spcode='130',0.6,0))/100) 有了一个就不愁其他
      

  2.   

    select count(*),(feecode*0.8/100) AS s_125, (feecode*0.6/100) AS s_103 from table where (spcode="125" or  spcode="103") group by spcode, fee
      

  3.   

    如果我想求出某一时间spcode=125时feecode*0.8与spcode=103时feecode*0.6的和(feecode*0.8+feecode*0.6),用一个语句怎么写呢?要按时间分组,求出比如:
    2006-06-15 feecode*0.8+feecode*0.6 
    2006-06-16 feecode*0.8+feecode*0.6
    2006-06-17 feecode*0.8+feecode*0.6
    求的是每一天的收益和不是整个月的收入和
      

  4.   

    sum(if(spcode='125',feecode*0.8/100, 0)+if(spcode='130',feecode*0.6/100,0))
    按日期分组
      

  5.   


    select fromtime,count(*), fee = case when spcode='125' then feecode*0.8/100 when spcode='03' then feecode*0.8/100 else feecode end from table
      

  6.   


    select fromtime,count(*), fee = case when spcode='125' then feecode*0.8/100 when spcode='103' then feecode*0.6/100 else feecode end from table
      

  7.   

    select fromtime,count(*), fee = case when spcode='125' then feecode*0.8/100 when spcode='103' then feecode*0.6/100 else feecode end from table