Solve by sql.