I have a table "campaign_items" with columns (budget spent), and I want to calculate the remaining budget using the formula remaining budget = budget - spent
Now I run a query:
select distinct a.budget,a.spent
from campaign_items a
where campaign_item_id=12345
order by a.budget-a.spent
But I get an error message:
ERROR: for SELECT DISTINCT, ORDER BY expressions should appear in the select list
Note. I cannot remove the keyword DISTINCTfrom the request because the request is created using JdbcTemplate
Can someone help me deal with this error?
source
share