重命名内部联接并将其用于后续的内部联接
Renaming an inner join and using it for a subsequent inner join
所以我有三个 table。
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
和 business.name
。
我考虑过在 user
和 review
上进行内部联接,条件是 user.id = review.user_id
,其中 user.id in (select id from user where review_count > 10)
。这将在仅选择属于已撰写超过 10 条评论的用户的那些 user.id
后,对上述 table 执行内部联接。接下来我希望对这个新的 table 和 business
table 执行内部连接,条件是 business.id = new_table.business_id
,其中 new_table
是 [=35] =] 通过对评论和用户执行之前的内部连接获得。
我知道我的重命名语法可能有问题。
我收到语法错误: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;
下面的查询应该与您要执行的查询相同。
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
所以我有三个 table。
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
和 business.name
。
我考虑过在 user
和 review
上进行内部联接,条件是 user.id = review.user_id
,其中 user.id in (select id from user where review_count > 10)
。这将在仅选择属于已撰写超过 10 条评论的用户的那些 user.id
后,对上述 table 执行内部联接。接下来我希望对这个新的 table 和 business
table 执行内部连接,条件是 business.id = new_table.business_id
,其中 new_table
是 [=35] =] 通过对评论和用户执行之前的内部连接获得。
我知道我的重命名语法可能有问题。
我收到语法错误: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;
下面的查询应该与您要执行的查询相同。
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