dprlv04662 2014-10-17 09:50
浏览 28

提取1周时间间隔的记录,当新周开始时,他们开始下一个计时器

I am using the query given below to extract the records for 1 Week Time interval.

 mysql_query("SELECT t1.username, SUM(t2.points) AS total 
    FROM actcontest t2 JOIN user t1 ON t1.userid = t2.userid WHERE t2.date
    BETWEEN (CURDATE() - INTERVAL 1 WEEK) AND CURDATE()  GROUP BY t1.username ORDER BY 
    total DESC LIMIT 20");

Once the records are fetched I am using the different query to award bonuses to the top 3 users.

This works fine.

Problem: Once bonus has been awarded to the last week, top 3 members, new dates shall start from the new week starting dates, where last week ended.

suppose: we started the timer on date: [dd/mm/yy]
Week 1 = {01-01-2010 to 07/01/2010}
Week 2 = {07-01-2010 to 14/01/2010}
Week 3 = {14-01-2010 to 21/01/2010}
Week 4 = {21-01-2010 to 28/01/2010}

Can you please help me in building this logic for my script. I am using php and Mysql.

What I want to Do:
One i have awarded bonus to week one winners. I want timer to start fetching the members for the next week only, It should not include the previous dates .

I hope i clarified the question.

  • 写回答

2条回答 默认 最新

  • dscw1223 2014-10-17 10:59
    关注

    Consider something like this:

    SET @weekNo := 4;
    SET @dateStart := '2014-01-01';
    
    SELECT ADDDATE(CONCAT(@dateStart, ' 00:00:00'), INTERVAL 7*(@weekNo-1) DAY),
        ADDDATE(CONCAT(@dateStart, ' 23:59:59'), INTERVAL 7*@weekNo-1 DAY);
    

    You can check the above script in sql. You can change the 2 variables at the top: @weekNo is the week you need to compute the date interval since the start date. And the @dateStart is the date the timer started.

    In your php code you can compute the date by replacing the dateStart and weekNo with php variables.

    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来