小编Ala*_*man的帖子

postgreSQL 不按顺序排序

我有这个 postgreSQL 查询,它应该返回

由 comment_date 排序的前 3 条评论来自

按 post_date 排序的前 10 个帖子表...

出于某种原因,它不是按 post_date 订购的:

with a as 
      (
          SELECT  
           posts.post_id as post_id 
          FROM posts where user_id = 'user1'
          order by post_date desc --this is not working
          limit 10
      ), b as
      (
          select user_id,
          comment_id,
          post_id,
          comment_date
          , ROW_NUMBER() over (partition by post_id order by comment_date desc) as RowNum
          from post_comments
      ) 
        SELECT * from a 
     INNER JOIN b USING (post_id)
      where b.RowNum <= 3
Run Code Online (Sandbox Code Playgroud)

示例:https : …

sql postgresql

0
推荐指数
1
解决办法
30
查看次数

标签 统计

postgresql ×1

sql ×1