所以我有三张桌子。
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.id
s 和s。business.name
我考虑过在whereuser
和review
条件下进行内部连接。这将在仅选择属于已撰写超过 10 条评论的用户的那些之后对上述表格执行内部联接。接下来我想对这个新表和表进行一次内连接,条件是,前一次对review和user进行内连接得到的表在哪里。user.id = review.user_id
user.id in (select id from user where review_count > 10)
user.id
business
business.id = new_table.business_id
new_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;