如何在postgreSQL中执行此SQL查询?

如何在postgreSQL中执行此SQL查询?,postgresql,Postgresql,如何在PostgreSQL中执行此查询 我在SQL中的尝试 SELECT stories.* where user.id = 1 AND user.id = usersources.userid AND usersources.id = source.id AND source.id = story.id AND (story.id = user.id

如何在PostgreSQL中执行此查询

我在SQL中的尝试

SELECT stories.*
        where 
            user.id = 1 AND 
            user.id = usersources.userid AND 
            usersources.id = source.id AND 
            source.id = story.id 
            AND (story.id = user.id) IS NOT IN actions table  
文本解释

SELECT
    stories
WHERE
 they have a relationship to a source AND
 sources has a story AND
 there IS NOT a row in actions from user and story (aka already acted on story)
上下文

SELECT
    stories
WHERE
 they have a relationship to a source AND
 sources has a story AND
 there IS NOT a row in actions from user and story (aka already acted on story)
这是一个用户可以订阅多个新闻源的应用程序 浏览新闻。一旦用户浏览新闻,他们就不能再浏览了 再次看到那个新闻报道

表格的视觉效果


好的,我想这会让你达到你的标准

SELECT s.*
FROM stories s
INNER JOIN actions a ON s.id = a.storyid
INNER JOIN sources s1 ON s.id = s1.id
INNER JOIN usersources us ON s1.id = us.sourceid
INNER JOIN users u ON us.userid = u.id
WHERE u.id = 1 
AND u.id != a.userid

好的,我想这会让你达到你的标准

SELECT s.*
FROM stories s
INNER JOIN actions a ON s.id = a.storyid
INNER JOIN sources s1 ON s.id = s1.id
INNER JOIN usersources us ON s1.id = us.sourceid
INNER JOIN users u ON us.userid = u.id
WHERE u.id = 1 
AND u.id != a.userid

我闻到了家庭作业的味道不:)这实际上是我的iOS应用程序。我想今天发布,但我有一个黑客的方式和300毫秒的响应时间:D只是想澄清这个问题。我闻到了家庭作业的味道否:)这实际上是我的iOS应用程序。我想今天发布,但我有一个黑客方式,响应时间为300ms:D,只是想澄清这个问题。我认为你需要
左连接动作
不存在()
,因为现在你要求这个故事已经有人演过了,只是不是通过
u.id=1
。hmmm似乎没有返回任何内容:(我认为您需要
左连接操作
不存在()
,因为现在您要求该故事已经由某人执行,而不是通过
u.id=1
。hmmm似乎没有返回任何内容:(