久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <tfoot id='YE5q7'></tfoot>

    <small id='YE5q7'></small><noframes id='YE5q7'>

    <i id='YE5q7'><tr id='YE5q7'><dt id='YE5q7'><q id='YE5q7'><span id='YE5q7'><b id='YE5q7'><form id='YE5q7'><ins id='YE5q7'></ins><ul id='YE5q7'></ul><sub id='YE5q7'></sub></form><legend id='YE5q7'></legend><bdo id='YE5q7'><pre id='YE5q7'><center id='YE5q7'></center></pre></bdo></b><th id='YE5q7'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='YE5q7'><tfoot id='YE5q7'></tfoot><dl id='YE5q7'><fieldset id='YE5q7'></fieldset></dl></div>
    • <bdo id='YE5q7'></bdo><ul id='YE5q7'></ul>

    1. <legend id='YE5q7'><style id='YE5q7'><dir id='YE5q7'><q id='YE5q7'></q></dir></style></legend>
    2. 如何在 Laravel 5 中使用 orderBy Desc 獲得平均值

      How to get average with orderBy Desc in Laravel 5(如何在 Laravel 5 中使用 orderBy Desc 獲得平均值)

      <small id='xTS1r'></small><noframes id='xTS1r'>

        <tbody id='xTS1r'></tbody>
      <tfoot id='xTS1r'></tfoot>

        • <i id='xTS1r'><tr id='xTS1r'><dt id='xTS1r'><q id='xTS1r'><span id='xTS1r'><b id='xTS1r'><form id='xTS1r'><ins id='xTS1r'></ins><ul id='xTS1r'></ul><sub id='xTS1r'></sub></form><legend id='xTS1r'></legend><bdo id='xTS1r'><pre id='xTS1r'><center id='xTS1r'></center></pre></bdo></b><th id='xTS1r'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='xTS1r'><tfoot id='xTS1r'></tfoot><dl id='xTS1r'><fieldset id='xTS1r'></fieldset></dl></div>
            • <bdo id='xTS1r'></bdo><ul id='xTS1r'></ul>
              • <legend id='xTS1r'><style id='xTS1r'><dir id='xTS1r'><q id='xTS1r'></q></dir></style></legend>
                本文介紹了如何在 Laravel 5 中使用 orderBy Desc 獲得平均值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我的數據庫中有 2 個表.

                I have 2 tables in my database.

                booksratings

                書籍id, name

                評級

                idbook_idrating

                我已經為這些模型設置了很多關系.

                i have set has many relationship for these models.

                所以在 Book 模型中 -

                So in Book model -

                public function ratings()
                {
                    return $this->hasMany('AppRating');
                }
                

                Rating 模型 -

                public function book()
                {
                    return $this->belongsTo('AppBook');
                }
                

                現在我想獲取所有具有平均評分但按高評分排序的書籍.

                Now i want to fetch all books with there average rating but order by high rating.

                所以我先給書評分高,然后評分低.

                so i high rated books first and then low ratings.

                那么我如何加入 2 個表來實現這個結果.

                So How i can join 2 tables to achieve this result.

                謝謝.

                推薦答案

                您可以使用修改后的 withCount():

                You can use a modified withCount():

                $books = Book::withCount(['ratings as average_rating' => function($query) {
                    $query->select(DB::raw('coalesce(avg(rating),0)'));
                }])->orderByDesc('average_rating')->get();
                

                這篇關于如何在 Laravel 5 中使用 orderBy Desc 獲得平均值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)
                  <tbody id='2DWXw'></tbody>

                    <tfoot id='2DWXw'></tfoot>

                      <i id='2DWXw'><tr id='2DWXw'><dt id='2DWXw'><q id='2DWXw'><span id='2DWXw'><b id='2DWXw'><form id='2DWXw'><ins id='2DWXw'></ins><ul id='2DWXw'></ul><sub id='2DWXw'></sub></form><legend id='2DWXw'></legend><bdo id='2DWXw'><pre id='2DWXw'><center id='2DWXw'></center></pre></bdo></b><th id='2DWXw'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='2DWXw'><tfoot id='2DWXw'></tfoot><dl id='2DWXw'><fieldset id='2DWXw'></fieldset></dl></div>
                      <legend id='2DWXw'><style id='2DWXw'><dir id='2DWXw'><q id='2DWXw'></q></dir></style></legend>
                      • <bdo id='2DWXw'></bdo><ul id='2DWXw'></ul>

                        <small id='2DWXw'></small><noframes id='2DWXw'>

                        1. 主站蜘蛛池模板: 99精品久久久国产一区二区三 | 综合色婷婷 | 黄色在线免费观看 | 免费日韩网站 | 中文字幕亚洲一区二区va在线 | 热久久免费视频 | aaaaaaa片毛片免费观看 | 欧美一级黄色片 | 二区不卡 | 精品不卡 | 亚洲午夜av| 一级亚洲| 四虎成人免费视频 | 黑人一级黄色大片 | 国产精品99999999 | 一区二区在线不卡 | 97精品超碰一区二区三区 | 午夜成人免费视频 | 欧美a级成人淫片免费看 | 日本特黄a级高清免费大片 特黄色一级毛片 | 亚洲一区二区在线视频 | 91视频中文 | www.蜜桃av | 天天综合91 | 精品久久久久久久久久久久 | 一级毛片免费看 | 日韩一区二区三区在线视频 | 色99视频| 国产久| 欧美高清视频一区 | 亚洲另类春色偷拍在线观看 | 国产一区二区精品在线 | 涩涩导航 | 久久99精品久久久久久国产越南 | 亚洲精品乱码久久久久久按摩 | 久久免费大片 | 久久大陆 | 免费午夜电影 | 性做久久久久久免费观看欧美 | 亚洲欧美日韩精品 | 国产91丝袜 |