x-tasks Queries online: postgre http://sqlfiddle.com/#!17/4cd31/4 sqlite http://sqlfiddle.com/#!5/eecf6/1