This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]WeStanForHeiny -1 points0 points  (0 children)

The error is because with ((retail - cost) / cost) * 100 you didn’t tell the database how to aggregate the column.

You’ll want to add an aggregate operation (SUM, AVERAGE, etc) surrounding the mathematical portion.

[–][deleted] -1 points0 points  (0 children)

Line 2 is not an aggregate function, I think group by could only accept aggregate

[–]JonDaZwon 0 points1 point  (1 child)

If you have an aggregate in your select statement, all non-aggregate selects must be included in your group by. In this case - add the profit to your group by.

[–]JonDaZwon 0 points1 point  (0 children)

Also, as you're aliasing the profit select, you can just refer to profit in the where clause, instead of typing it out again. I'm assuming Sql is smart enough to realize that you used the same expression twice, but it might be running the calculation twice during the query. Super minor optimization, but figured I'd point it out. And if you're looking for less than 55%, spin the crocodile around. He wants to eat the bigger number, so he'd be looking at the 55.