如何从Postgres上的表中交叉数据 [英] How to INTERSECT datas from tables on postgres
问题描述
INTERSECT命令
遇到一些问题。希望有人能帮助我。
I'm having some problems with INTERSECT command
. Hope someone could help me.
我想获取出现在第一和第二个 SELECT
中的movieid。之后,我想使用这些数据(可能在 LIMIT
中为10)在另一个表中接收电影的标题。
I want to get the the movieid that appears in the first and second SELECT
. After that I want to use these data (that could be in a LIMIT
of 10) to receive the titles of the movie in another table.
类似这样的东西,但我做得不好:
Something like this, but I'm not doing right:
SELECT movieid
FROM ratings
WHERE votes > 0
INTERSECT SELECT movieid FROM genres WHERE genre = '$_SESSION[genero]'
In
在此之后,我要获取这些movieid,并在表中搜索movieid,最后显示标题。谢谢!
After this, I want to get these movieids and search the table movies for the movieid and finally show the title. Thank you!
推荐答案
据我所知,我认为这就是您要寻找的东西
As far as I understood the question, I think this is what you are looking for
select title , movieid from movies
where movieid in
(
SELECT movieid FROM ratings
WHERE votes > 0
INTERSECT
SELECT movieid FROM genres
WHERE genre = '$_SESSION[genero]'
)
这篇关于如何从Postgres上的表中交叉数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!