Может снять квадратные скобки и as
может помочь вам:
select product.id, t2.tt
from
product
join (
select product_id, avg(rating) tt
from reviews
where -- Your where conditions for the reviews table
) t2 on product.id = t2.product_id
where -- More where conditions
Кроме того, рассмотреть не используя подзапрос. Если ваш запрос так же, как это, вы могли так что-то более простое:
select product.id, avg(reviews.rating) tt
from
product
join reviews on product.id = reviews.product_id
where -- All the conditions you need to define
Если есть строки в product
таблицы, которые не имеют соответствия записей в reviews
таблице, но вы все еще хотите, чтобы они были на результат , рассмотреть вопрос об использовании left join
:
select product.id, avg(reviews.rating) tt
from
product
left join reviews on product.id = reviews.product_id
where
reviews.product_id is null
or reviews.product_id is not null and (
-- All the conditions you need to define for the matching rows in the
-- reviews table
)
Mysql, sql server, oracle? – Mihai
Попробуйте удалить '[]' – Mihai
Мне нужно это в oracle Я думаю, я использую SQLite atm – user3795356