0

I am having a table course and columns as place and cost with more than two rows.

I want my query to display the course which has the highest cost. I tried with the below query

select splace 
from studies 
group by splace 
having max(ccost);

and got the error as argument of HAVING must be type boolean, not type integer

What mistake I have done? And What would be the correct query?

Dan Field
  • 20,885
  • 5
  • 55
  • 71
zeewagon
  • 1,835
  • 4
  • 18
  • 22
  • SELECT splace FROM Studies ORDER BY ccost DESC LIMIT 1 – Mihai Dec 29 '15 at 13:54
  • 1
    Among other things, you need `having max(ccost)` equal to something, or greater than something, etc. – Dan Bracuk Dec 29 '15 at 13:56
  • 1
    You either don't need the grouping or don't need the having. What do you actually want to achieve here? Get the highest ccost for each splace, or get the splace with the highest cost? – Dan Field Dec 29 '15 at 13:56
  • The query select place from studies where cost = ( select max(cost) from studies ) worked out – zeewagon Dec 29 '15 at 14:37

2 Answers2

3
select  place
from    studies
where   cost = 
        (
        select  max(cost)
        from    studies
        )
Andomar
  • 232,371
  • 49
  • 380
  • 404
  • What about the grouping? This is the correct answer assuming the asker just wants the (s)place with the highest (c)cost, but not if they're trying to do something else... – Dan Field Dec 29 '15 at 13:53
  • If they were trying to do something else, the question would not have included, `I want my query to display the course which has the highest cost.`. – Dan Bracuk Dec 29 '15 at 18:04
0

If you only want one row, then you can use limit and order by:

select place
from studies
order by cost desc
limit 1;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786