Even more SQL fixes

In particular this improves the generation of Summary objects on top of other selections and then cleans up the generation of By's using these.

A lot of good would be had if we found a simple answer to this http://stackoverflow.com/questions/25914329/rearrange-columns-in-sqlalchemy-select-object