GnuCash SQL Examples

From GnuCash
Revision as of 11:36, 14 March 2021 by MaestroGlanz (talk | contribs) (Request all child accounts of a given account)
Jump to: navigation, search

Introduction

Request all child accounts of a given account

This request will result in a list of the start account and all children and grand*x*children. The snippet is based on a snippet from sql-workbench.


with recursive account_tree as (
   select guid, parent_guid
   from accounts
   where guid = 'Start account'  -- this defines the start of the recursion
   union all
   select child.guid,
          child.parent_guid
   from accounts as child
     join account_tree as parent on parent.guid = child.parent_guid -- the self join to the CTE builds up the recursion
)
select * from account_tree;