我的表(data)中字段如下:
 num(字符型)  name(字符型) date(日期) late(bit/布而)   absent(bit)...
我想用一条sql语句把一段时间的迟到(late),缺席(absent)为真的记录用count()统计出来,和num ,name这些字段一起显示在一个表里面。
我原先的语句如下:
  select num,name,count(date) as 迟到 ,count(absent) as 缺席 from data where date>''+datetostr(bdate)+'' and date<''+datetostr(edate)+'' and 
   late=1 or ...
bdate 起始时间  edate 截止时间 
上面代码错误多多。语法上和逻辑上都有错误。
各位师兄,帮帮忙哈。 
给点代码:

解决方案 »

  1.   

    是sql server吧?!sql='select num,name,sum(cast(late as int)) as 迟到 ,sum(cast(absent as int)) as 缺席 from data where date>'''+datetostr(bdate)+''' and date<'''+datetostr(edate)+''' group by  num,name'....
      

  2.   

    select num,name,sum(cast(b1 as int)) as 迟到 ,sum(cast(b2 as int)) as 缺席 
    from table2 where rq>='2002-10-10' and rq<='2002-10-22' group by  num,name以上调试通过
      

  3.   

    老兄,日期最好进行格式化,format(),否则极容易出错。
      

  4.   

    同意楼上的,但是如果不是sql server,你就需要把查询迟到和缺席作为一个子查询放在你查询的select内。
      

  5.   

    谢了,  我想请问一下cast()和lif()的功能是什么?
    还有我在sql sever 中有一个时间(time)字段,是datetime型的,当我只输入时间时, 系统会自动添上日期在前面,有啥办法把前面的日期给去了喃?? 
      

  6.   

    你的引号又问题:
    select num,name,count(date) as 迟到 ,count(absent) as 缺席 from data where date>‘''+datetostr(bdate)+''' and date<'''+datetostr(edate)+''' and 
       late=1 or ...
    这样的语句很久没见过了,在SQL里居然可以运行,好!