0

这可以通过一个查询来完成吗?

餐桌日:

dID
enable
holiday
fewMore

表段:

d_ID //foregn key to day->dID
startTime
endTime
fewMore

询问:

SELECT dID, enabled,holiday,  
       TIME_TO_SEC(dHaurs) as wsTimeHHmm,
       DATE_FORMAT(dDate, '%d') as dateForComparing,
       DATE_FORMAT(start, '%H:%i') as startTime,
       DATE_FORMAT(end, '%H:%i') as endTime 
FROM day d                                  
LEFT JOIN segment ws 
ON ws.d_ID = d.dID
WHERE dDate BETWEEN '" . $startDate . "' AND  '" . $endDate . "'                                
ORDER by dateForComparing

结果我得到:

dID:10, start time:08:00, end time:09:00, holiday:0, enabled:1
dID:10, start time:09:00, end time:10:00, holiday:0, enabled:1
dID:11, start time:08:00, end time:10:00, holiday:1, enabled:1

但我想用相同的 d_ID 对所有段进行分组。

dID:10, array((start time:08:00, end time:09:00),(start time:09:00, end time:10:00)), holiday:0, enabled:1

我试过GROUP_CONCAT(wsID,start, end)......GROUP BY dID但我不确定这是正确的方式,而且我也无法使用功能DATE_FORMAT(start, '%H:%i') as startTime

这只能用mysql来完成吗?

更新:现在,我正在从结果创建数组:

  $returnData  [] =array(array(dID =>"dID",
                         endTime => $end_time,
                         startTime=> $start_time,...
                               ),
                        array( enabled=> $enabled,
                                holiday =>$holiday
                               )
                         );
echo json_encode($returnData);
4

1 回答 1

0

你不能在 MySQL 中返回数组,但你可以像这样操作输出:

dID:10, start time:08:00, end time:10:00, holiday:0, enabled:1
于 2013-01-26T19:34:49.720 回答