我想每天查看营业额摘要。
这是mySQL-Query:
SELECT
o.date_purchased,
round(ot.value,2)
FROM orders o
JOIN orders_total ot ON ot.orders_id = o.orders_id
WHERE o.date_purchased <= '2012-05-12'
AND o.date_purchased >= '2012-04-12'
AND ot.class = 'ot_total'
结果我在购买日期获得了10个订单。 但是我也会在没有营业额的时期内得到这样的日子,比如这个例子: 2012-04-12 0,00 2012-04-13 120,95 2012-04-14 0,00
格尔茨 罗恩
答案 0 :(得分:0)
试试这个
$todayDate = date("Y-m-d");
$today = strtotime($todayDate);
$nextmonth = mktime(0, 0, 0, date("m")+1, date("d"), date("Y"));
然后在查询中使用此变量
SELECT
o.date_purchased,
round(ot.value,2)
FROM orders o
JOIN orders_total ot ON ot.orders_id = o.orders_id
WHERE o.date_purchased <= $today
AND o.date_purchased >= $nextmonth
AND ot.class = 'ot_total'
您也可以使用
SELECT
o.date_purchased,
round(ot.value,2)
FROM orders o
JOIN orders_total ot ON ot.orders_id = o.orders_id
WHERE ot.class = 'ot_total'
AND o.date_purchased BETWEEN $today AND $nextmonth
答案 1 :(得分:0)
只能通过更改查询来执行您想要的操作,因为SQL不会在它们根本不存在时添加行。
两种可能的解决方案:
orders
表格进行外部联接,尽管这样做通常没有意义。