也許去除方括號和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