select * from...where name=...
union()....

解决方案 »

  1.   

    TO :metal11516580(金属狂人)
    谢谢!!
    按你说的方法,如果表中很多名称,不是要写N个UNION语句??
    有其它方法吗?
      

  2.   

    use tempdb
    go
    select 名称=(case  when 价格 in(select min(价格) from test group by 名称
                                 
                                 ) then 名称 else '' end) 
    ,日期,价格
     from test a
      

  3.   

    select 名称=(case  when 价格 in(select min(价格) from test group by 名称) then 名称 else '' end) 
    ,日期,价格
     from test a order by 日期 desc,名称
      

  4.   

    chinaandys(风流泪&VS&雨含笑)的办法倒是个好主意,但是如果最小的价格有两个相同的时候,就又不符合楼主的要求了
      

  5.   

    select identity(int,1,1) as id,名称,日期,价格
    into #t
    from 表名 
    group by 名称,日期,价格select 名称=case 
                     when id in (select min(id) from #t group by 名称) then 名称
                     else '' 
                     end
    ,日期,价格
    from #t
    drop table #t
      

  6.   

    可以建立一个唯一索引ID IDENTITY(INT,1,1)
    select 名称=(case  when ID in(select min(ID) from test group by 名称 ) then 名称 else '' end) 
    ,日期,价格
     from test a order by 日期 desc,名称
      

  7.   

    搞错,改一下:
    select identity(int,1,1) as id,名称,日期,价格
    into #t
    from 表名 select 名称=case 
                     when id in (select min(id) from #t group by 名称) then 名称
                     else '' 
                     end
    ,日期,价格
    from #t
    drop table #t
      

  8.   

    select 名称=(case  when 日期+价格 in (select min(日期+价格) from test group by 名称) then 名称 else '' end) 
    ,日期,价格
     from test a order by 日期 desc,名称
      

  9.   

    select 名称=(case  when cast(日期 as varchar)+cast(价格 as varchar) in (select min(cast(日期 as varchar)+cast(价格 as varchar)) from test group by 名称) then 名称 else '' end) 
    ,日期,价格
     from test a order by 日期 desc,名称
      

  10.   

    select 名称=(case  when 价格 in(select min(价格) from test group by 名称) then 名称 else '' end) 
    ,日期,价格
     from test a order by 日期 desc,名称
      

  11.   

    TO  chinaandys(风流泪&VS&雨含笑)
    谢谢,我试了一下,不对呀
      

  12.   

    select identity(int,1,1) as id,名称,日期,价格
    into #t
    from 表名 --不要排序select 名称=(case 
                     when id in (select min(id) from #t group by 名称) then 名称
                     else '' 
                     end)
    ,日期,价格
    from #t
    drop table #t
      

  13.   

    create table tb(名称 varchar(10),日期 datetime,价格 int)
    insert into tb
              select '搜狐','2004-12-22',12
    union all select '网易','2004-12-30',18
    union all select '网易', '2004-12-29',20
    union all select '搜狐', '2004-12-24',22
    union all select '搜狐', '2004-12-25',25
    union all select '新浪', '2004-12-29',52
    union all select '网易','2004-12-21',100
    select identity(int,1,1) as id,名称,日期,价格 into #t FROM tb ORDER BY 名称,日期select (case when id in (select min(id) from #t group by 名称) then 名称 else '' end) AS 名称
           ,日期,价格
    FROM #t  --不要排序
    搜狐 2004-12-22 00:00:00.000 12
    2004-12-24 00:00:00.000 22
    2004-12-25 00:00:00.000 25
    网易 2004-12-21 00:00:00.000 100
    2004-12-29 00:00:00.000 20
    2004-12-30 00:00:00.000 18
    新浪 2004-12-29 00:00:00.000 52
      

  14.   

    多谢xf8zbf(瞎想) ( ) 信誉:100