enchance SQL, fix bug
Signed-off-by: Jurets <jurets75@gmail.com>