fix sql for missed cases.