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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog