我现在要做个打卡任务系统用户领取连续打卡30天的任务 , 中间有一天没打卡就任务失败这个SQL该怎么写啊,希望大虾们写详细点,谢谢

解决方案 »

  1.   

    第一,限制每个人每天只能打一次卡
    第二:select count(*)  as cnt from 打卡记录 where createdate>=开始 and createdate<=结束。最后判断cnt是否大于30 
      

  2.   

    select count(distinct 日期) from ...........这个日期是不带时间的varchar字段,否则要做处理。
      

  3.   

    SQL Server问题去SQL Server论坛去问吧,那里更专业一些。
    给你一个知识:凡是带有“全部”这个算子的计算,如果你没有现成的工具已经封装了它,那么就要转换为“不存在”这个算子来计算。比如查询“每一天都没有迟到”就要转换为对这个查询“存在某一天,这一天迟到了”的否定。凡是all(select * from .....)的查询,如果你的关系数据库没有现成的all子查询功能,就要转换为 not exists(select * from .....)的查询。
      

  4.   


    这是太........如果是专门学过sql课程,那么你的老师看来没有多少文化。
      

  5.   

    基本的逻辑公里,再学有关于算法、sql之类的东西是应该学到的基本的设计知识,用“否定之否定”的方式来解决那些概括性的查询,这是常识。或许你学sql的时候,你的老师只是给你讲sql server手册上的语法,而不是教你设计(各种使用sql的关系数据库都通用的)sql查询设计基础知识。
      

  6.   


    select count(distinct(convert(varchar(12), CREATE_TIME,102)))
    from t_func
    where FUNC_CREATE_TIME is not null
    and 日期条件1.注意日期要格式化到"日"在disticnt排重.
    2.空日期要排掉
      

  7.   

    ------第一种返回总数-----
    select count(date)as '总数' from (
    select convert(varchar(10),a.regdate,112) as date from userinfo a inner join dbo.UserInfoDetail b 
    on a.userid=b.userid where b.parentuserid=1 and a.regdate between 
    '2010-12-17 00:00:00' and '2012-12-19 00:00:00' group by convert(varchar(10),a.regdate,112)) a----第二种返回条数-------
    select convert(varchar(10),a.regdate,112) as date,* from userinfo a inner join dbo.UserInfoDetail b 
    on a.userid=b.userid where b.parentuserid=1 and a.regdate between 
    '2010-12-17 00:00:00' and '2012-12-19 00:00:00'我写了2种方法查询的  现在我不晓得后台该怎么判断哪一天没打卡,用死办法可以写,要是天数多了就麻烦了
      

  8.   

    打卡第一次计算开始时间,DaetTime.adddays或SQL  dateadd计算30天后时间
    select  *  from tb where 时间差
      

  9.   

    select top 1 1 from table where  刷卡=false and 日期>30天前的日期
    如果有记录就表示"非全勤"
    如果没有记录就表示"全勤"