0

I am using laravel framework. i want to get the count of MySQL count occurrences of id. Here is my problem. My table name is download_histories. Here is my record for demo :-

Table:- download_histories
id   alt_image_id   
1       25  
2       25
3       26
4       27  
5       29
6       26  

Now look at the table. Now this table having 6 records and alt_image_id 25 coming twice times and alt_image_id 26 coming twice times .and 27 and 29 coming once . Now i want the result when group of alt_image count is greater then equal to 2. Now i want the count of groupby records can anyone help me. I want the count that is 2

i have done so far :-

DB::table('download_histories')
        ->select(DB::raw('count(download_histories.user_id) as totaluserdownload'))
        ->groupby('alt_image_id')
        ->having('totaluserdownload','>=',2)
        ->get();

Note : i want the count not get the data . Please help me. Thanks in advance :) enter image description here

kunal
  • 4,122
  • 12
  • 40
  • 75

0 Answers0