profit query changed in sql with view table