generate query sql for mysql