SQL Server Error in SQL : Only one expression can be specified in the select list when the subquery is not introduced with EXISTS

bcs8qyzn  于 2023-08-02  发布在  其他
关注(0)|答案(1)|浏览(196)

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
kg7wmglp

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 the in operator, the subquery should only return the values you are trying to match title_id with.

相关问题