Subject | Re: [firebird-support] Common Table Expressions and Sorting |
---|---|
Author | masotti |
Post date | 2009-04-21T07:47:42Z |
Hi Stefan,
Stefan Heymann ha scritto:
dept_tree (dept_id, lvl, name, sign )
as (
select dept_id, name, 0, 0 as lvl
from depts where parent_dept_id is null
union all
select d.dept_id, d.name, h.lvl + 1, 1
from depts d
join dept_tree h on d.parent_dept_id = h.dept_id
-- *1*
)
select z.dept_id, z.lvl, z.name
from dept_tree z
order by z.sign, upper(z.name)
Ciao.
Mimmo.
Stefan Heymann ha scritto:
> with recursivewith recursive
> dept_tree as (
> select dept_id, name, 0 as lvl
> from depts where parent_dept_id is null
>
> union all
>
> select d.dept_id, d.name, h.lvl + 1
> from depts d
> join dept_tree h on d.parent_dept_id = h.dept_id
> -- *1*
> )
> select dept_id, lvl, name
> from dept_tree
>
dept_tree (dept_id, lvl, name, sign )
as (
select dept_id, name, 0, 0 as lvl
from depts where parent_dept_id is null
union all
select d.dept_id, d.name, h.lvl + 1, 1
from depts d
join dept_tree h on d.parent_dept_id = h.dept_id
-- *1*
)
select z.dept_id, z.lvl, z.name
from dept_tree z
order by z.sign, upper(z.name)
Ciao.
Mimmo.