rewrite view sql