xssbook2/db/rest/post/api_post.sql

26 lines
407 B
MySQL
Raw Normal View History

CREATE VIEW api.post AS
SELECT
p.id,
p.user_id,
p.content,
p.date,
COALESCE(c.cc, 0)
AS comment_count
FROM
2024-03-30 16:14:42 +00:00
admin.post p
LEFT JOIN (
SELECT
COUNT(c.id) as cc,
c.post_id
FROM
admin.comment c
GROUP BY
c.post_id
) c ON p.id = c.post_id
ORDER BY p.id DESC;
GRANT SELECT ON TABLE api.post
TO rest_anon, rest_user;
GRANT SELECT ON TABLE admin.post
TO rest_anon, rest_user;