有一个表,有两列,第一列是日期(Day),第二列是价格(Price)
要求仅使用SQL语句列出每年的最高价和最低价
要把最高价和最低价所对应的日期也一起列出来

解决方案 »

  1.   

    select * from tt a where not exists(select 1 from tt
    where year(Day)=year(a.Day) and a.Price>Price)
    or
    not exists(select 1 from tt
    where year(Day)=year(a.Day) and a.Price<Price)
      

  2.   

    select *
    from tb A
    where not exists(select 1 from tb B where where year(A.day)=year(B.day) and A.price<B.price)
      

  3.   

    select *
    from 有一个表 a
    where not exists (select 1 from 有一个表 where year(日期)=year(a.日期) and 价格<a.价格)
    or not exists (select 1 from 有一个表 where year(日期)=year(a.日期) and 价格>a.价格)
      

  4.   

    抱歉,偶回复晚了
    请问“tt a”是什么意思?
    假定a上表名,tt是什么意思?
    偶试了一下,好像不行
      

  5.   

    tt是你的表名  a是tt的别名