簡體   English   中英

如何在Laravel 5.4中進行此查詢?

[英]How to do this query in Laravel 5.4?

查詢是:

SELECT * FROM `noticias` WHERE `fecha` in ( select `fecha` from `noticias` group by `fecha` having count(*) > 1)

我正在嘗試這種形式:

DB::table('noticias')->groupBy('fecha')->having('fecha', '>', 1)->get();

但是這給了我錯誤: SQLSTATE [42000]:語法錯誤或訪問沖突: noticias '不在GROUP BY中(SQL:選擇*來自noticias group by fecha having fecha > 1)

謝謝!

您的查詢將轉換為查詢構建器,如下所示:

DB::table("noticias")
   ->whereIn('fecha', function ($q) {
        return $q->from('noticias')->select("fecha")
                 ->groupBy("fecha")
                 ->having(DB::raw("count(*)"), ">", 1);
   })->get();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM