番号           日期
1AG2CAM0149-A 2005-10-2
1AG2CAM0149-A 2005-10-3
1AG2CAM0149-A 2005-10-4
1AG2CAM0177-- 2005-10-5
1AG2CAM0177-- 2005-10-6
1AG2CAM0177-- 2005-10-7
1AG2CRM0270-C 2005-10-8
1AG2CRM0270-C 2005-10-9
1AG2CRM0270-C 2005-10-10
1AG2CRM0271-A 2005-10-11
1AG2CRM0271-A 2005-10-12
1AG2CRM0271-A 2005-10-13
1AG2CRM0272-A 2005-10-14
1AG2CRM0272-A 2005-10-15
找出番号的最后日期,也是最大日期

解决方案 »

  1.   

    select 番号,max(日期) as 日期 from 表 group by 番号
      

  2.   

    select 番号,max(日期) as maxriqi from tablename
      

  3.   

    select 番号,max(日期) as maxriqi from tablename group by 番号
      

  4.   

    select 番号,max(日期) as 日期 from 表 group by 番号
      

  5.   

    select 番号,max(日期) as 日期 from 表 group by 番号来晚了,jf
      

  6.   

    问一个问题,我的CSDN答不开,所以在这里提,分数我在另外加
    表1
    ALLNAME(字段名)
    湖北大田公司
    中国房产公司 表2
    NAME(字段名)
    房产
    现需要找出在表2中有简称的企业名称,也即中国房产公司 我写的
    select table1.allname,table2.[name]
    from table1,table2 
    where table1.allname like '%'+table2.[name]+'%' 
    怎么不行呀,用子查询也不行呀?
    谢谢急用,50分另外给!!!!!!!!
      

  7.   

    select 番号,max(日期) as 日期 from 表 group by 番号
      

  8.   

    To yumanqing:
    select table1.ALLNAME from table1,table2 where instr(table1.ALLNAME ,table2.NAME) > 0
      

  9.   

    难道不成是这样
    番号            日期                                                     
    ------------- ------------------------------------------------------ 
    1AG2CAM0149-A 2005-10-04 00:00:00.000
    1AG2CAM0177-- 2005-10-07 00:00:00.000
    1AG2CRM0270-C 2005-10-10 00:00:00.000
    1AG2CRM0271-A 2005-10-13 00:00:00.000
    1AG2CRM0272-A 2005-10-15 00:00:00.000(所影响的行数为 5 行)不是要找日期最大的么  还是我建的表有问题啊
      

  10.   

    yumanqing(共同学习(学习ing)) 表1
    ALLNAME(字段名)
    湖北大田公司
    中国房产公司 表2
    NAME(字段名)
    房产declare @s as varchar(20)
    select @s = select top 1 name from 表2
    set @s = '%' + @s + '%'
    select * from 表1 where allname like @s