Postgres Sql Using Variables To Solve