0

所以我有三张桌子。

1) business:
-> id           (varchar)  id of business
-> name         (varchar)  name of business

2) review:
-> business_id  (varchar)  id of reviewed business
-> user_id      (varchar)  id of user who reviewed

3) user:
-> id           (varchar)  id of user
-> name         (varchar)  name of user
-> review_count (int)      number of reviews written by the user

我想写一个查询,提取那些已经被那些写了超​​过 10 条评论的用户评论过的企业的business.ids 和s。business.name

我考虑过在whereuserreview条件下进行内部连接。这将在仅选择属于已撰写超过 10 条评论的用户的那些之后对上述表格执行内部联接。接下来我想对这个新表和表进行一次内连接,条件是,前一次对review和user进行内连接得到的表在哪里。user.id = review.user_iduser.id in (select id from user where review_count > 10)user.idbusinessbusiness.id = new_table.business_idnew_table

我了解我的重命名语法可能存在问题。

我收到语法错误:Error: near "where": syntax error。我正在使用 sqlite3。

这是我到目前为止所拥有的。

select business.id, business.name
from business inner join  
(                  
review inner join user
on review.user_id = user.id
where user.id in (
select id
from user
where review_count > 10) 
) as R
on R.business_id = business.id;
4

1 回答 1

1

下面的查询应该与您尝试执行的操作相同。

select business.id, business.name
from business                 
inner join review on review.business_id = business.id
inner join user on user.id = review.user_id 
where user.review_count > 10
于 2015-10-06T16:06:03.430 回答