app/Statistics/Repository/IndividualRepository.php
public function statsAgeQuery(string $related = 'BIRT', string $sex = 'BOTH', int $year1 = -1, int $year2 = -1)
    {
        $prefix = DB::connection()->getTablePrefix();

        $query = $this->birthAndDeathQuery($sex);

        if ($year1 >= 0 && $year2 >= 0) {
            $query
                ->whereIn('birth.d_type', ['@#DGREGORIAN@', '@#DJULIAN@'])
                ->whereIn('death.d_type', ['@#DGREGORIAN@', '@#DJULIAN@']);

            if ($related === 'BIRT') {
                $query->whereBetween('birth.d_year', [$year1, $year2]);
            } elseif ($related === 'DEAT') {
                $query->whereBetween('death.d_year', [$year1, $year2]);
            }
        }

        return $query
            ->select(DB::raw($prefix . 'death.d_julianday2 - ' . $prefix . 'birth.d_julianday1 AS days'))
            ->orderBy('days', 'desc')
            ->get()
            ->all();
    }
public function statsAgeQuery(string $related = 'BIRT', string $sex = 'BOTH', int $year1 = -1, int $year2 = -1)
    {
        $prefix = DB::connection()->getTablePrefix();

        $query = $this->birthAndDeathQuery($sex);

        if ($year1 >= 0 && $year2 >= 0) {
            $query
                ->whereIn('birth.d_type', ['@#DGREGORIAN@', '@#DJULIAN@'])
                ->whereIn('death.d_type', ['@#DGREGORIAN@', '@#DJULIAN@']);

            if ($related === 'BIRT') {
                $query->whereBetween('birth.d_year', [$year1, $year2]);
            } elseif ($related === 'DEAT') {
                $query->whereBetween('death.d_year', [$year1, $year2]);
            }
        }

        return $query
            ->select(DB::raw($prefix . 'death.d_julianday2 - ' . $prefix . 'birth.d_julianday1 AS days'))
            ->orderBy('days', 'desc')
            ->get()
            ->all();
    }
public function statsAgeQuery ( string $ related = 'BIRT' , string $ sex = 'BOTH' , int $ year1 = - 1 , int $ year2 = - 1 ) { $ prefix = DB :: connection ( ) -> getTablePrefix ( ) ; $ query = $ this -> birthAndDeathQuery ( $ sex ) ; if ( $ year1 >= 0 && $ year2 >= 0 ) { $ query -> whereIn ( 'birth.d_type' , [ '@#DGREGORIAN@' , '@#DJULIAN@' ] ) -> whereIn ( 'death.d_type' , [ '@#DGREGORIAN@' , '@#DJULIAN@' ] ) ; if ( $ related === 'BIRT' ) { $ query -> whereBetween ( 'birth.d_year' , [ $ year1 , $ year2 ] ) ; } elseif ( $ related === 'DEAT' ) { $ query -> whereBetween ( 'death.d_year' , [ $ year1 , $ year2 ] ) ; } } return $ query -> select ( DB :: raw ( $ prefix . 'death.d_julianday2 - ' . $ prefix . 'birth.d_julianday1 AS days' ) ) -> orderBy ( 'days' , 'desc' ) -> get ( ) -> all ( ) ; }
General query on ages.

@param string $related
@param string $sex
@param int    $year1
@param int    $year2

@return array|string
General query on ages .