EnginePower
is derived and doesn't mean anything yet within the context of that query -- it's just an alias. You could overcome this by evaluating the same expression as above:
case
when (SELECT SUM(engineParts) FROM Engine WHERE Car.engine = Engine.type) >= 30
then 'yes'
else 'no'
end as canDrive
Or even better by wrapping it in a common table expression/subquery:
with cte as (
SELECT
Car.name,
(SELECT SUM(engineParts) FROM Engine WHERE Car.engine = Engine.type) AS enginePower
FROM Car
)
select name, enginePower, case when enginePower >= 30 then 'yes' else 'no' end as canDrive
from cte
Or better yet, perhaps, just convert your scalars into a standard join:
select
c.name, sum (engineParts) as enginePower,
case when sum (engineParts) >= 30 then 'yes' else 'no' end as hasPower
from
car c
left join engine e on
c.engine = e.type
group by
c.name