[英]MySQL SELECT WHERE Multiple values
I have a table like this 我有一张这样的桌子
Creating google charts, so i need couple of DB queries to create JSON. 创建谷歌图表,所以我需要几个数据库查询来创建JSON。 Everything is done but having hard time with DB query. 一切都完成了,但是很难进行数据库查询。
Currently i have single query, 目前我有一个查询,
$json = array();
$sql = "SELECT SUM(TIME_TO_SEC(`hours`)) as seconds,date FROM `am_am2_time_tracking` WHERE is_billable = 1 GROUP BY date";
$result = $conn->query($sql);
while($row = $result->fetch_assoc())
{
$bil_hours = floatval($row['seconds'] / 60 / 60);
$json[] = array('date'=>$row['date'],'bill_hours'=>$bil_hours);
}
echo json_encode($json);
which gives me this json: 这给了我这个json:
[{"date":"2016-02-03","bill_hours":12.5},{"date":"2016-02-04","bill_hours":6},{"date":"2016-02-12","bill_hours":3},{"date":"2016-02-13","bill_hours":4},{"date":"2016-02-18","bill_hours":1.25},{"date":"2016-02-19","bill_hours":1},{"date":"2016-02-26","bill_hours":1.75},{"date":"2016-02-27","bill_hours":0.5}]
But instead of creating new query, looking for better way to have both hours in single json. 但是,与其创建新查询,不如寻找一种更好的方式将两个小时都放在单个json中。
您是否尝试进行以下查询
$sql = "SELECT SUM(TIME_TO_SEC(`hours`)) as seconds,date FROM `am_am2_time_tracking` GROUP BY date, is_billable";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.