app/Statistics/Repository/FamilyRepository.php
private function ageBetweenSiblingsQuery(int $total): array
    {
        $prefix = DB::connection()->getTablePrefix();

        return DB::table('link AS link1')
            ->join('link AS link2', static function (JoinClause $join): void {
                $join
                    ->on('link2.l_from', '=', 'link1.l_from')
                    ->on('link2.l_type', '=', 'link1.l_type')
                    ->on('link2.l_file', '=', 'link1.l_file');
            })
            ->join('dates AS child1', static function (JoinClause $join): void {
                $join
                    ->on('child1.d_gid', '=', 'link1.l_to')
                    ->on('child1.d_file', '=', 'link1.l_file')
                    ->where('child1.d_fact', '=', 'BIRT')
                    ->where('child1.d_julianday1', '<>', 0);
            })
            ->join('dates AS child2', static function (JoinClause $join): void {
                $join
                    ->on('child2.d_gid', '=', 'link2.l_to')
                    ->on('child2.d_file', '=', 'link2.l_file')
                    ->where('child2.d_fact', '=', 'BIRT')
                    ->whereColumn('child2.d_julianday2', '>', 'child1.d_julianday1');
            })
            ->where('link1.l_type', '=', 'CHIL')
            ->where('link1.l_file', '=', $this->tree->id())
            ->distinct()
            ->select(['link1.l_from AS family', 'link1.l_to AS ch1', 'link2.l_to AS ch2', DB::raw($prefix . 'child2.d_julianday2 - ' . $prefix . 'child1.d_julianday1 AS age')])
            ->orderBy('age', 'DESC')
            ->take($total)
            ->get()
            ->all();
    }
private function ageBetweenSiblingsQuery(int $total): array
    {
        $prefix = DB::connection()->getTablePrefix();

        return DB::table('link AS link1')
            ->join('link AS link2', static function (JoinClause $join): void {
                $join
                    ->on('link2.l_from', '=', 'link1.l_from')
                    ->on('link2.l_type', '=', 'link1.l_type')
                    ->on('link2.l_file', '=', 'link1.l_file');
            })
            ->join('dates AS child1', static function (JoinClause $join): void {
                $join
                    ->on('child1.d_gid', '=', 'link1.l_to')
                    ->on('child1.d_file', '=', 'link1.l_file')
                    ->where('child1.d_fact', '=', 'BIRT')
                    ->where('child1.d_julianday1', '<>', 0);
            })
            ->join('dates AS child2', static function (JoinClause $join): void {
                $join
                    ->on('child2.d_gid', '=', 'link2.l_to')
                    ->on('child2.d_file', '=', 'link2.l_file')
                    ->where('child2.d_fact', '=', 'BIRT')
                    ->whereColumn('child2.d_julianday2', '>', 'child1.d_julianday1');
            })
            ->where('link1.l_type', '=', 'CHIL')
            ->where('link1.l_file', '=', $this->tree->id())
            ->distinct()
            ->select(['link1.l_from AS family', 'link1.l_to AS ch1', 'link2.l_to AS ch2', DB::raw($prefix . 'child2.d_julianday2 - ' . $prefix . 'child1.d_julianday1 AS age')])
            ->orderBy('age', 'DESC')
            ->take($total)
            ->get()
            ->all();
    }
private function ageBetweenSiblingsQuery ( int $ total ) : array { $ prefix = DB :: connection ( ) -> getTablePrefix ( ) ; return DB :: table ( 'link AS link1' ) -> join ( 'link AS link2' , static function ( JoinClause $ join ) : void { $ join -> on ( 'link2.l_from' , '=' , 'link1.l_from' ) -> on ( 'link2.l_type' , '=' , 'link1.l_type' ) -> on ( 'link2.l_file' , '=' , 'link1.l_file' ) ; } ) -> join ( 'dates AS child1' , static function ( JoinClause $ join ) : void { $ join -> on ( 'child1.d_gid' , '=' , 'link1.l_to' ) -> on ( 'child1.d_file' , '=' , 'link1.l_file' ) -> where ( 'child1.d_fact' , '=' , 'BIRT' ) -> where ( 'child1.d_julianday1' , '<>' , 0 ) ; } ) -> join ( 'dates AS child2' , static function ( JoinClause $ join ) : void { $ join -> on ( 'child2.d_gid' , '=' , 'link2.l_to' ) -> on ( 'child2.d_file' , '=' , 'link2.l_file' ) -> where ( 'child2.d_fact' , '=' , 'BIRT' ) -> whereColumn ( 'child2.d_julianday2' , '>' , 'child1.d_julianday1' ) ; } ) -> where ( 'link1.l_type' , '=' , 'CHIL' ) -> where ( 'link1.l_file' , '=' , $ this -> tree -> id ( ) ) -> distinct ( ) -> select ( [ 'link1.l_from AS family' , 'link1.l_to AS ch1' , 'link2.l_to AS ch2' , DB :: raw ( $ prefix . 'child2.d_julianday2 - ' . $ prefix . 'child1.d_julianday1 AS age' ) ] ) -> orderBy ( 'age' , 'DESC' ) -> take ( $ total ) -> get ( ) -> all ( ) ; }
Returns the ages between siblings.

@param int $total The total number of records to query

@return array
Returns the ages between siblings .