从titles表中显示出最高价和最低价的书名的价格(无限制条数,但价格只有两种价格,且显示出的只有两种价格的书)
我用:
select title, price from titles having price=max(price) or price=min(price) 查询报错.
请教各位大侠哈!

解决方案 »

  1.   

    select title, price from titles
    Where price = (Select max(price) From titles)
    Or price = (Select min(price) From titles)
      

  2.   

    Select '最高价: ' as kind,title, price from titles as a
     where not exists(Select * from titles where price>a.price)
    Union all
    Select '最低价: ' as kind,title, price from titles as a
     where not exists(Select * from titles where price<a.price)
      

  3.   

    Or
    select title, price from titles
    Where price = (Select max(price) From titles)
    Union All
    select title, price from titles
    Where price = (Select min(price) From titles)
      

  4.   

    --try
    select title, price from titles ta
    where not exists (select 1 from titles where  price>ta.price)
    union all
    select title, price from titles ta
    where not exists (select 1 from titles where  price<ta.price)