Working with the relational DB - OpenSlides/OpenSlides GitHub Wiki
Building queries
This can be done with the help of psycopg3's sql. This can be done easier with python-sql, showing a lot of examples. In their forum you may find some more informations, if needed.