1. count 메서드 - 행 수 세기:
$totalRows = DB::table('posts')->count();
이 코드는 posts 테이블의 전체 행 수를 세는 데 사용됩니다.
$publishedCount = DB::table('posts')->where('is_published', true)->count();
이 코드는 is_published 열이 true인 행의 수를 세는 데 사용됩니다.
2. sum 메서드 - 특정 열의 합 계산:
$totalMinutesToRead = DB::table('posts')->sum('min_to_read');
이 코드는 min_to_read 열의 값의 합계를 계산합니다.
3. avg 메서드 - 특정 열의 평균 계산:
$averageMinutesToRead = DB::table('posts')->avg('min_to_read');
이 코드는 min_to_read 열의 값의 평균을 계산합니다.
$averagePublishedMinutes = DB::table('posts')->where('is_published', true)->avg('min_to_read');
avg 메서드를 where 메서드와 결합하여 특정 조건을 충족하는 행에 대한 평균을 계산할 수 있습니다.
4. max 메서드 - 최대값 찾기:
$maxMinutesToRead = DB::table('posts')->max('min_to_read');
이 코드는 min_to_read 열에서 최대값을 찾습니다.
5. min 메서드 - 최소값 찾기:
$minMinutesToRead = DB::table('posts')->min('min_to_read');
이 코드는 min_to_read 열에서 최소값을 찾습니다.