Github Sort By Sql Statement With If Condition In Javascript