In the query, you count the number of purchased unique products.
Obviously, if you are trying to calculate the total number of purchased products, then you need to sum up the quantity and make a left join.
$orders = DB::table('orders')
->selectRaw(
'users.name as user_name, sum(orders.total) as total, sum(order_product.quantity) as total_products'
You are right! These are 2 different statistics you might encounter. In one case, you care about the unique product count, while in other case - you care about the actual SKUs amount (not unique products) :)
For our goal it was just unique products, but in real life - you do see a variaty of calculations
M
Modestas
✓ Link copied!
Hi, I have updated the lesson and added an automated test with our repository link. This should solve the issue that we had here.
In the query, you count the number of purchased unique products. Obviously, if you are trying to calculate the total number of purchased products, then you need to sum up the quantity and make a left join.
You are right! These are 2 different statistics you might encounter. In one case, you care about the unique product count, while in other case - you care about the actual SKUs amount (not unique products) :)
For our goal it was just unique products, but in real life - you do see a variaty of calculations
Hi, I have updated the lesson and added an automated test with our repository link. This should solve the issue that we had here.