Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
select title, price, case
when pub_id in (
select pub_id
from publishers
where state = 'ca') then price * 1.1
when title_id in (
select title_id
from titleauthor
group by title_id
having count(au_id) > 1) then price * 1.05
when title_id in (
select title, sum(qty*price) NewPrice
from titles t
inner join sales s on t.title_id = s.title_id
group by title
having sum(qty*price) > 500) then Price * 1.02
else price * 1.01
end NewPrice
from titles
1条答案
按热度按时间kg7wmglp1#
Remove the [NewPrice] column from you third
when
's subquery.It is ok to keep it in the
having
clause for filtering purposes, but since you are using thein
operator, the subquery should only return the values you are trying to matchtitle_id
with.