select 线名,杆名,日期 from yourtable group by 线名,杆名,日期

解决方案 »

  1.   

    我自己搞定了,
    谢谢楼上的大哥!不过他的也错掉了,可是他给了我提示,还是要谢谢他.
    具体的实现如下
    select 线名,杆名,max(日期)
    from tablename
    group by 线名,杆名,日期
      

  2.   

    感觉不用group by 3个字段。group by 线名,杆名就够了
      

  3.   

    select 线名,杆名,max(日期)
    from tablename
    group by 线名,杆名
      

  4.   

    现在还有个问题了.
    假如我基础表加了几个字段如下:
    原始表数据如下:
    线名 杆号 日期            a   b    c     d
    a 1 2003-01-01      1   1    1     1
    a 1 2002-01-01      2   2    2     2
    a 1 2001-01-01      3   3    3     3
    a 2 2003-01-01      4   4    4     4
    a 2 2002-01-01      5   5    5     5
    a 2 2001-01-01      6   6    6     6
    b 1 2003-01-01      7   7    7     7 
    b 1 2002-01-01      8   8    8     8
    b 2 2003-01-01      9   9    9     9
    b 2 2002-01-01      10  10   10    10
    要得到的结果如下:
    线名 杆号 日期          a    b    c    d
    a 1 2003-01-01    1    1    1    1 
    a 2 2003-01-01    4    4    4    4 
    b 1 2003-01-01    7    7    7    7
    b 2 2003-01-01    9    9    9    9
    现在该要怎么做呢?????  
      

  5.   

    select 线名,杆名,日期,min(a),min(b),min(c),min(d)
    from tablename
    group by 线名,杆名,日期
      

  6.   

    不行的啊,txlicenhe.不过谢谢你的回话.
      

  7.   

    有人告诉我是这样子做的:
    select 线名,杆号,max(日期),
    (select a from tablename t2 where t1.线名=t2.线名 and t1.杆号=t2.杆号 and t1.日期=t2.日期) as a1,
    (select b from tablename t3 where t1.线名=t3.线名 and t1.杆号=t3.杆号 and t1.日期=t3.日期) as b1,
    (select c from tablename t4 where t1.线名=t4.线名 and t1.杆号=t4.杆号 and t1.日期=t4.日期) as c1,
    (select d from tablename t5 where t1.线名=t5.线名 and t1.杆号=t5.杆号 and t1.日期=t5.日期) as d1
    from tablename t1
    group by 线名,杆名  
    不过也是不行的给出的错误信息是:试图执行的查询中不包含作为合计函数一部分的特定表达式"日期"这又是为什么呢???
    这个问题真的那么难解决吗??
    请高手们帮帮我啊.
    我快要郁闷死了.!!!!!!!
      

  8.   

    select t1.xm,t1.gh,t1.rq,t1.a,t1.b,t1.c,t1.d from table1 t1 inner join (select xm,gh,max(rq) as rq2 from table1 group by xm,gh) t2 on t1.xm=t2.xm and t1.gh=t2.gh  and t1.rq=t2.rq2