sql: define count on selects
Cleaner SQL generation

Build function lower_column which grabs the lowest valid representation
of a sqlaclhemy column.

Apply this function throughout the code to avoid unnecessary nested
subqueries

The issue here is that if we make a select, e.g.

    sel = select(table).where(table.c.amount < 0)

Then all future column gets from this selection refer to this table,
we're forced to do nested queries, even when unnecessary.   So for example

    sel.group_by(sel.c.name)

Is nested. What we really wanted was the following

    sel.group_by(table.c.name)

lower_column is a function that transforms

    sel.c.name -> table.c.name

which makes our generation much happier