大家好,
    我有一个问题:
    有一个表有三个列:
    书名     价格    日期
     a        1.5     2009.11.1
     a        1.3     2009.11.2
     a        1.1     2009.11.4
     b        3.5     2009.11.1
     b        3       2009.11.3
     c        10      2009.11.2
     c        8       2009.11.5书按照日期不同的价格,当然以最新的日期的价格生效
那么,我如何找出以上的最新的日期的所有书的价格,及对该价格统一下降10%请各位高手不吝赐教,谢谢

解决方案 »

  1.   

    select 书名,
           价格*0.9,
           日期
    from tb t 
    where not exists(select 1 from tb where 书名=t.书名 and  日期>t.日期)
      

  2.   

    select *
    from ta a 
    where not exists(select 1 from ta where 书名 = a.书名 and 日期 > a.日期 )
      

  3.   

    --> Title  : Generating test data [tb]
    --> Author : wufeng4552
    --> Date   : 2009-11-06 11:40:12
    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb] (书名 nvarchar(2),价格 numeric(8,2),日期 datetime)
    insert into [tb]
    select 'a',1.5,'2009.11.1' union all
    select 'a',1.3,'2009.11.2' union all
    select 'a',1.1,'2009.11.4' union all
    select 'b',3.5,'2009.11.1' union all
    select 'b',3,'2009.11.3' union all
    select 'c',10,'2009.11.2' union all
    select 'c',8,'2009.11.5'
    select 书名,
           价格*0.9 价格,
           日期
    from tb t 
    where not exists(select 1 from tb where 书名=t.书名 and  日期>t.日期)
    /*
    书名   价格                                      日期
    ---- --------------------------------------- -----------------------
    a    0.990                                   2009-11-04 00:00:00.000
    b    2.700                                   2009-11-03 00:00:00.000
    c    7.200                                   2009-11-05 00:00:00.000(3 個資料列受到影響)
    */
      

  4.   

    select A.* from ta A
    where not exists(select 1 from ta where 书名 = A.书名 and 日期 > A.日期 )
      

  5.   

    select 
      书名,
      价格*0.9 as 价格,
      日期
    from 
      tb t 
    where
      not exists(select 1 from tb where 书名=t.书名 and  日期>t.日期)
      

  6.   

    不好意思,能帮忙讲一下,这个是什么原理吗,
    另外,select 不能对 表 的数据生效啊