Re: Reporting by family tree - Mailing list pgsql-novice
From | Ibrahim Shaame |
---|---|
Subject | Re: Reporting by family tree |
Date | |
Msg-id | CAJOWwD7YmD8jPediD7qG49vq9mtTbJOx3eAV4a9234RTJe_aHw@mail.gmail.com Whole thread Raw |
In response to | Re: Reporting by family tree (swastik Gurung <gurung_swastik@yahoo.com>) |
Responses |
Re: Reporting by family tree
|
List | pgsql-novice |
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;
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 |
I suppose you ought to be using, recursive CTE queriesDocumentation can be found at: 7.8. WITH Queries (Common Table Expressions)
7.8. WITH Queries (Common Table Expressions)
7.8. WITH Queries (Common Table Expressions) # 7.8.1. SELECT in WITH 7.8.2. Recursive Queries 7.8.3. Common Tabl...
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 by date: