0
0
Laravelframework~10 mins

Aggregates (count, sum, avg) in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to count all users in the database.

Laravel
$count = User::[1]();
Drag options to blanks, or click blank then click option'
Asum
Bcount
Cavg
Dmax
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() instead of count()
Using avg() which calculates average
2fill in blank
medium

Complete the code to get the total price of all orders.

Laravel
$total = Order::[1]('price');
Drag options to blanks, or click blank then click option'
Acount
Bmin
Csum
Davg
Attempts:
3 left
💡 Hint
Common Mistakes
Using count() which counts rows
Using avg() which calculates average
3fill in blank
hard

Fix the error in the code to calculate the average age of users.

Laravel
$averageAge = User::[1]('age');
Drag options to blanks, or click blank then click option'
Asum
Bmax
Ccount
Davg
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() or count() instead of avg()
4fill in blank
hard

Fill both blanks to count users older than 30.

Laravel
$count = User::where('age', [1], [2])->count();
Drag options to blanks, or click blank then click option'
A>
B<
C30
D25
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>'
Using wrong number like 25
5fill in blank
hard

Fill all three blanks to get the average price of products cheaper than 100.

Laravel
$average = Product::where('price', [1], [2])->[3]('price');
Drag options to blanks, or click blank then click option'
A<
B100
Cavg
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<'
Using sum() instead of avg()