I am writing inner join query and calculating count and average rating using formula of count
and avg
of mysql. This query is run in mysql but it gives error in laravel.
What changes can I make in code? I need changes in my query.
The Error:
"(2/2) QueryException
SQLSTATE[42000]: Syntax error or access violation: 1055
'ecommerce.table_sub_category.sub_category_id'
isn't in GROUP BY (SQL: select table_rating_review.product_id,COUNT(*)
as count_review,avg(rating) as rating, table_sub_category.sub_category_id,
table_product.brand_id,table_product.product_id,
table_product.product_name, table_product.product_image,table_product.product_price
from table_sub_category inner join table_product
on table_sub_category.sub_category_id=table_product.sub_category_id inner join table_rating_review on table_product.product_id=table_rating_review.product_id where
table_sub_category.sub_category_id=1 group by table_rating_review.product_id)"
My query:
$get_product_details=
DB::select('select table_rating_review.product_id,COUNT(*) as count_review,avg(rating)
as rating,table_sub_category.sub_category_id,table_product.brand_id,table_product.product_id,table_product.product_name,table_product.product_image,table_product.product_price from table_sub_category inner join table_product on table_sub_category.sub_category_id=table_product.sub_category_id inner join table_rating_review on table_product.product_id=table_rating_review.product_id where table_sub_category.sub_category_id=? group by table_rating_review.product_id',[$sub_category_id]);