dpd7195 2013-07-23 23:23
浏览 25
已采纳

找出mysql中两个日期之间的值的频率

Hi with the follow code I request what dates are all in my database without duplicates. Then I save it to an array. In the array I also need an other value.

The value I need is how much users are in one day in the database without duplicates. For Example the array must later lookslike 23.07.2013 - 10, 24.07.2013 - 50 (users). I search for several hours but I don't find a good mysql query.

$query = "SELECT id, user, timestamp FROM stat WHERE timestamp BETWEEN '$datum1' AND '$datum2' GROUP BY timestamp";
$result = mysql_query($query,$db);

while($row = mysql_fetch_assoc($result))
    {
        mysql_num_rows($result);
        $dataset1[] = array(strtotime($row['timestamp']),$number_of_users_on_this_day);
    }
  • 写回答

1条回答 默认 最新

  • dourui9570 2013-07-23 23:33
    关注

    Try:

    $query = "SELECT id, user, COUNT(*) as count FROM stat WHERE timestamp BETWEEN '$datum1' AND '$datum2' GROUP BY timestamp";

    This will return the number of entries in the value 'count'

    if you want distinct data, in place of * use

    COUNT(DISTINCT id)

    with whatever field you want to be unique in place of 'id'

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号