dongsou3041 2012-11-18 13:32
浏览 93
已采纳

通过Timestamp条目聚合和可视化SQLite数据库中的条目

I have a big SQLite - Database that contains entries like this:

rowID   timestamp    employee  sold         
1       1345294648   myer      1
2       1351508109   miller    2          
3       1351508109   smith     8
4       1351508109   miller    10
5       1351508109   smith     1
6       1353243448   myer      10

It represents the amount of units certain employees have sold at a certain time.

With the following code in php i can get the sold units per employee:

<?php

$response = array();
$db = new PDO("sqlite:./db.sqlite");

$query_count = $db -> query("SELECT * FROM myTable GROUP BY employee");

while ($row = $query_count -> fetch(PDO::FETCH_ASSOC)) {

$current_employee = $row['employee'];

$response[$current_employee]["sold"] = $row['sold'];

}

echo json_encode($response);

?>

This will give back the following JSON - formatted data:

{ 
  "miller" : { "sold" : 12 },
  "myer" : { "sold" : 11 },
  "smith" : { "sold" : 9 }
}

Now i want to separate the sales to the distinct months, like this:

{
   "miller":{
      "sold":{
         "january":1,
         "february":8,
         "march":9
      }
   },
   "myer":{
      "sold":{
         "january":10,
         "february":11,
         "march":13
      }
   },
   "smith":{
      "sold":{
         "january":11,
         "february":10,
         "march":10
      }
   }
}

After that, i want to visualize the data with an bar chart, like this but non-stacked:

http://bl.ocks.org/1134768

Is there a SQL - Request / PHP-Script that can help me?

I'm glad for every answer, thanks in advance.

  • 写回答

1条回答 默认 最新

  • duanli9001 2012-11-19 08:16
    关注

    SQLite delivers different date functions, to aggregate data by dates:

    http://www.sqlite.org/lang_datefunc.html

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

报告相同问题?

悬赏问题

  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))