wiki:UseCase18

Version 1 (modified by 226026, 30 hours ago) ( diff )

--

Преглед на сите дискусии за даден топик

Актери

  • Ненајавен корисник

Чекори

  • Навигира до соодветниот топик.
  • Се прикажуваат сите дискусии во рамки на тој топик.

SQL

create or replace view v_discussion_thread
as
with recursive
    depth_table as
        (select parent_id, id, 0 as depth
         from discussion_thread
         UNION ALL
         select discuss.parent_id, dpth.id, dpth.depth + 1
         from depth_table dpth
                  join discussion_thread discuss
                       on dpth.parent_id = discuss.id),
    tmp as (select id, max(depth) as depth
            from depth_table
            group by id)
select d.id as id, t.user_id as user_id, d.depth as depth, d1.parent_id as parent_id, t.created_at as "created_at"
from tmp d
         join depth_table d1
              on d.id = d1.id and d1.depth = d.depth
         join thread t
              on t.id = d.id;
Note: See TracWiki for help on using the wiki.