-1
我有以下查詢:差分輸出
SELECT BIL_Date,
SUM(BIL_Rate * BIL_Quantity) AS sumRevAccomodation,
COUNT(*) AS total_nights
FROM `___BillableDatas`
WHERE BIL_HotelId = 'AAA00'
AND BIL_Date BETWEEN "2017-04-10" AND "2017-04-18"
AND BIL_Type = "Night"
AND BIL_Status != "Cancelled"
GROUP BY BIL_Date ASC
......這給了我這樣的結果......
+------------+--------------------+--------------+
| BIL_Date | sumRevAccomodation | total_nights |
+------------+--------------------+--------------+
| 2017-04-10 | 285.00 | 3 |
| 2017-04-11 | 285.00 | 3 |
| 2017-04-12 | 305.00 | 3 |
| 2017-04-13 | 310.00 | 3 |
| 2017-04-14 | 205.00 | 2 |
| 2017-04-15 | 180.00 | 2 |
| 2017-04-16 | 180.00 | 2 |
| 2017-04-17 | 190.00 | 2 |
| 2017-04-18 | 190.00 | 2 |
+------------+--------------------+--------------+
但此代碼後的第一個值是小姐:
$fetch = $query->fetch();
$count = $query->rowCount();
if($count >= 1) {
while ($fetch = $query->fetch(PDO::FETCH_ASSOC)) {
$bills[] = [
'BIL_Date' => $fetch['BIL_Date'],
'BIL_Revenues' => $fetch['sumRevAccomodation'],
'BIL_NightNb' => $fetch['total_nights']
];
}
}
什麼問題?
http://sqlfiddle.com/#!9/7594a8/1
感謝。
這就是所有的代碼? – Strawberry
在第二部分之後,「$ bills」不包含「2017-04-10」的信息。 –
'// $ fetch = $ query-> fetch();'註釋此行並嘗試 – Bhaskar