如何從代碼字中的mysql
db獲得銷售額的季度變化趨勢(3 months)
?從mysql獲取銷售額的季度趨勢
我有一個數據表
order
-id
-paid_date
-order_total
我想接收的數據是總訂單值的斜率,而不是簡單地將在最近3個月的訂單數。
型號代碼
$results = $this->db->query("SOME_SQL");
伊夫開始寫以下,但在難倒如何顯示的結果作爲斜率 ::其中90表示大致3個月
$day_seconds = 86400;
$period = 90 * $day_seconds;
$this->db->select('COUNT(*) AS total', false);
$this->db->select("FROM_UNIXTIME(`paid_date`, '%Y-%m-%d') AS date", false);
$this->db->where('paid_date >', time()-$period);
實施例預期輸出
輸出sho只有2個值才能顯示出趨勢。
$results = [ [ 0 => 44 ], [1=>88] ];
最好要需要的是知道,如果銷售的總收入是傾斜向上或向下,更高的正斜率表明大量增加銷售
例:
//Dramatic Increase of sales
$results = [ [ 0 => 22 ], [1=>150] ];
//Slow Increase of sales
$results = [ [ 0 => 50 ], [1=>55] ];
//Slow Decrease of sales
$results = [ [ 0 => 64 ], [1=>55] ];
預期結果是什麼?你能用言語告訴我們嗎? – Alfwed
好吧不好更新我的問題,但基本上我想知道在過去3個月總收入是傾向上升還是下降 – user1827093
與過去3個月前3個月相比? – Alfwed