Use aggregate functions for calculations and statistics.
use tommyknocker\pdodb\helpers\Db;
$total = $db->find()
->from('users')
->select(Db::count())
->getValue();$count = $db->find()
->from('users')
->select(Db::count('id'))
->getValue();$unique = $db->find()
->from('users')
->select(Db::count('DISTINCT country'))
->getValue();$total = $db->find()
->from('orders')
->select(Db::sum('amount'))
->where('status', 'completed')
->getValue();$average = $db->find()
->from('products')
->select(Db::avg('price'))
->getValue();$minPrice = $db->find()
->from('products')
->select(Db::min('price'))
->getValue();$maxPrice = $db->find()
->from('products')
->select(Db::max('price'))
->getValue();$stats = $db->find()
->from('orders')
->select([
'user_id',
'total_orders' => Db::count(),
'total_amount' => Db::sum('amount'),
'avg_amount' => Db::avg('amount')
])
->groupBy('user_id')
->get();$stats = $db->find()
->from('sales')
->select([
'total_sales' => Db::sum('amount'),
'total_orders' => Db::count(),
'avg_order' => Db::avg('amount'),
'min_order' => Db::min('amount'),
'max_order' => Db::max('amount')
])
->where('status', 'completed')
->getOne();- Aggregations - GROUP BY, HAVING
- Core Helpers - Essential helpers
- Numeric Helpers - Math functions