Rather than debug this complex version, try [the simpler alternative posted afterward](https://sqlite.org/forum/forumpost/ca5ed9a8f40e).
Rather than debug this complex version, try [the simpler alternative posted afterward](https://sqlite.org/forum/forumpost/ca5ed9a8f40e).