Re: Reporting by family tree

Поиск
Список
Период
Сортировка
От Ibrahim Shaame
Тема Re: Reporting by family tree
Дата
Msg-id CAJOWwD7YmD8jPediD7qG49vq9mtTbJOx3eAV4a9234RTJe_aHw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Reporting by family tree  (swastik Gurung <gurung_swastik@yahoo.com>)
Ответы Re: Reporting by family tree  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-novice
Swastik, thank you for the response. I started there, and have been stuck for many months now. I managed to get only father-child did not get further. Here is the example sql where I get father-child results.
With this code:
WITH RECURSIVE ukoo AS (
    SELECT namba,
         jina,
         baba,
         babu,
         nasaba_1,
         daraja
    FROM majina2
    WHERE majina2.nasaba_1 IN (SELECT DISTINCT namba FROM majina2)
 
UNION ALL
 
    SELECT mtoto.namba,
         mtoto.jina,
         mtoto.baba,
         mtoto.babu,
         mtoto.nasaba_1,
         daraja
    FROM majina2 mtoto
          WHERE mtoto.nasaba_1 NOT IN (SELECT DISTINCT namba FROM majina2)
 
)
 
SELECT  g.jina AS jina_la_mtoto,
        g.baba AS baba_wa_mtoto,
        g.babu AS babu_wa_mtoto,
        g.namba,
        mzazi.jina AS jina_la_mzazi,
        mzazi.baba AS jina_la_baba_la_mzazi,
        g.daraja
FROM ukoo g
JOIN majina2 mzazi
ON g.namba = mzazi.namba
ORDER BY g.namba;

I get:

jina_la_mtoto baba_wa_mtoto babu_wa_mtoto namba jina_la_mzazi jina_la_baba_la_mzazi daraja
---------------+---------------+---------------+--------+---------------+-----------------------+--------





Ibrahim Khamis Haji 100001 Ibrahim Khamis 6
Asia Khamis Haji 100002 Asia Khamis 6
Zubeir Khamis Haji 100003 Zubeir Khamis 6
Asha Mwinyi Bakari 100004 Asha Mwinyi 6
Mariama Mwinyi Bakari 100005 Mariama Mwinyi 6
Zainab Ibrahim Khamis 100006 Zainab Ibrahim 7
Fatma Ibrahim Khamis 100007 Fatma Ibrahim 7







Shaban Ibrahim Khamis 100162 Shaban Ibrahim 7
Alicia Shaban Ibrahim 100163 Alicia Shaban 8

Ideally I should get

Ibrahim (father of Shaban)
then Shaban the father of Alicia)
Under Shaban should get Alicia
Then Zainab (sister of Shaban
Then Fatma (sister of Shaban)
Then another member (after I have got Ibrahim and his descendants)

Any idea?



On Thu, Oct 5, 2023 at 4:15 PM swastik Gurung <gurung_swastik@yahoo.com> wrote:
On Thursday, 5 October 2023 at 16:44:46 GMT+5:45, Ibrahim Shaame <ishaame@gmail.com> wrote:


I have a table of members of a large family extendending back to eight generations. The current members contribute a monthly amount to the family fund. Only true descendants are included in the family list, no wives, no husbands. There are two tables

1 - Names with the following fields: idno (unique) --family member

parentid -- id number of the parent who connected the child to the family

etc

etc

2 – Contributions with fields: idno

etc

etc


Now I want to report Names and contributions par family tree: My ideal is to list grandfather, father, children based on the two fields (id, parentid).

Any suggestions?

Thanks in advance


В списке pgsql-novice по дате отправления:

Предыдущее
От: swastik Gurung
Дата:
Сообщение: Re: Reporting by family tree
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Reporting by family tree