ThinkPHP按月統計訂單總金額


基於ThinkPHP,按“月份”統計訂單表中的總金額

 

 數據表:(time:為年月日時分秒的時間戳,非時間戳時,用DATE_FORMAT)

實現樣式:

 

核心代碼:

$list = $m->where($where)
          ->field("SUM(`stream_money`) as stream_money,FROM_UNIXTIME(time,'%Y-%m') as months")
          ->group('months')
          ->limit($Page->firstRow.','.$Page->listRows)//分頁,用不到可省略
          ->order('months desc')
          ->select();

備注:(使用原生mysql語句實現)

         // 實例化一個空模型,沒有對應任何數據表
        $Dao = M();
        $sql = "SELECT FROM_UNIXTIME(time,'%Y%m') months,COUNT(id) COUNT,SUM(stream_money) stream_money FROM qp_dap_stream  WHERE type = 2 GROUP BY months desc";
        $res = $Dao ->execute($sql);   //主要針對執行curd    //返回影響行數
        $lists = $Dao->query($sql);

參考:https://segmentfault.com/a/1190000009304983?_ea=1885076


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM