mdofiy the sql and logic