Gravity: properly connect multiple conditional groups in SQL queries.