目前我能统计到日期1至日期2的所有产量工资合计,代码为 :sql = "select gh,xm,sum(val(price)) as price from cl where rq >=#" & CDate(DTPicker1.Value) & "# and rq<= #" & CDate(DTPicker2.Value) & "# group by gh,xm order by gh"  其中gh,xm,price,rq 字段分别为 工号、姓名、产量工资、日期 但领导要求还要统计到 日期1至日期2之间是星期天的产量工资合计?假设日期1是2011-3-1,日期2是2011-3-31,那就是要将2011-3-6,2011-3-13,2011-3-20,2011-3-27这四个星期天的产量工资给统计出来,请问代码如何更改呢?谢谢!!   

解决方案 »

  1.   

    sql = "select gh,xm,sum(val(price)) as price sum(if(WEEKDAY(rq)=6,price,0)) as sundayprice from cl where rq >=#" & CDate(DTPicker1.Value) & "# and rq<= #" & CDate(DTPicker2.Value) & "# group by gh,xm order by gh"
      

  2.   

    加条件
    and to_char(DTPicker1.Value,'day')='星期日'
      

  3.   

    2L修改一下ACCESS:
    sql = "select gh,xm,sum(val(price)) as price,sum(IIf(WEEKDAY(rq)=6,price,0)) as sundayprice from cl where rq >=#" & CDate(DTPicker1.Value) & "# and rq<= #" & CDate(DTPicker2.Value) & "# group by gh,xm order by gh"
      

  4.   


    谢谢 将你的代码带进去 算出来的工资怎么不对呀 好像不是周日的工资?请问这句sum(if(WEEKDAY(rq)=6,price,0)) as sundayprice 是什么意思?
      

  5.   

    在ACCESS中把6改为1就可以了,刚才6是在MYSQL中星期天的返回值。sum(if(WEEKDAY(rq)=1,price,0)) as sundayprice ,意思是:星期天的工资相加。