我可以在同一个父查询中使用子查询值吗?

时间:2016-12-19 07:11:55

标签: mysql

SELECT t.title, ( 
    SELECT AVG(star_rating) 
    FROM reviews r 
    WHERE r.id = t.id ) AS rating  
FROM table_1 t  
WHERE rating >= '4'
  

PHPMYADMIN显示错误 - > 'where中的未知列'评级'   条款“

1 个答案:

答案 0 :(得分:0)

试试这个;

SELECT t.title, 
       (SELECT AVG(star_rating) 
        FROM reviews r 
        WHERE r.id = t.id ) AS rating 
FROM table_1 t 
WHERE (SELECT AVG(star_rating) 
       FROM reviews r 
       WHERE r.id = t.id ) >= 4