Rewrite complex SQL query in partitions.inc to be friendly for older sqlite versions.
Rewrite complex SQL query in partitions.inc to be friendly for older sqlite versions.

jeffpiazza/derbynet,jeffpiazza/derbynet,jeffpiazza/derbynet,jeffpiazza/derbynet,jeffpiazza/derbynet,jeffpiazza/derbynet,jeffpiazza/derbynet