哪个表包含帖子URL?

我正在使用数据探索器构建一个查询,用于显示用户的帖子——我应该使用哪张表来获取帖子的 URL?我原本以为它在 posts 表中,但没找到。

这是我目前的查询:

SELECT u.email, c.name as post_category
 FROM posts p
left join user_emails u on p.user_id = u.user_id
left join topics t on p.topic_id=t.id
left join categories c on t.category_id = c.id
where p.created_at < '2021-03-01T00:00:00.000Z'
    GROUP BY
       u.email, u.user_id, c.name

谢谢。

在 SQL 中,它是:

'/t/-' || topics.id || '/' || posts.post_number

在您的示例中,这将变为:

SELECT u.email, c.name AS post_category, '/t/-' || t.id || '/' || p.post_number AS post_url
 FROM posts p
LEFT JOIN user_emails u ON p.user_id = u.user_id
LEFT JOIN topics t ON p.topic_id = t.id
LEFT JOIN categories c ON t.category_id = c.id
WHERE p.created_at < '2021-03-01T00:00:00.000Z'
    GROUP BY
       u.email, u.user_id, c.name

谢谢,太好了。

顺便提一下,带连字符的方式不起作用,所以我没有用这个:

'/t-/' || topics.id || '/' || posts.post_number

而是用了:

'/t/' || topics.id || '/' || posts.post_number

一切已解决 :+1: