假设记录
404121 8200400049/030 3 1000034706 112701160   4 10050    4 1160           
404121 8200400049/030 1 1000034706 112701160   4 10050    4 1330   如何将第三列中最大的取出来?
404121 8200400049/030 3 1000034706 112701160   4 10050    4 1160  
我怀疑是SQL的逻辑有错误了

解决方案 »

  1.   

    真的不明白你在说什么你上面那个是select 后的结果
    后面又来一句: 如何将第三列中最大的取出来?
    是什么意思?你不能举原表的数据来说明问题吗?
      

  2.   

    先说这步
    假设我表内容
    404121 8200400049/030 3 1000034706 112701160   4 10050    4 1160           
    404121 8200400049/030 1 1000034706 112701160   4 10050    4 1330  得到下面的结果
    404121 8200400049/030 3 1000034706 112701160   4 10050    4 1160 用max函数吗?
      

  3.   

    select * from 表 where 字段3=(select max(字段3) from 表)
      

  4.   

    表a 
    内容如下
    a      b       c     d
    1      3       4     5
    1      1       4     3
    1      2       5     5
    1      8       3     6当c列最大时,找b列为最大的记录也就是得到a      b       c     d
    1      2       5     5
      

  5.   

    是不是这样,当a相同时找c最大的行,如果c最大的行有多行则取b最大的那一行?
    若是则如下:
    select * from ta,(select a,max(c) c,max(b) b from ta group by a) tem
    where ta.a=tem.a and ta.c=tem.c and ta.b=tem.b
      

  6.   

    --测试--测试数据
    create table 表a(a int,b int,c int,d int)
    insert 表a select 1,3,4,5
    union  all select 1,1,4,3
    union  all select 1,2,5,5
    union  all select 1,3,5,5
    union  all select 1,8,3,6
    go--查询
    select a.*
    from 表a a join(
    select b=max(b),c from 表a
    where c=(select max(c) from 表a)
    group by c
    )b on a.b=b.b and a.c=b.c
    go--删除测试
    drop table 表a/*--测试结果
    a           b           c           d           
    ----------- ----------- ----------- ----------- 
    1           3           5           5(所影响的行数为 1 行)--*/
      

  7.   

    多谢!
    表a 
    内容如下
    a      b       c     d
    1      3       4     5
    1      1       4     3
    1      2       5     5
    1      8       3     6
    2      1       5     7
    2      3       5     6
    2      4       4     8得到记录 
    a      b       c     d
    1      2       5     5
    2      3       5     6下在好象得到的记录又太少了,在有的  a 列的没找见
      

  8.   

    on a.b=b.b and a.c=b.c---》
    on a.b=b.b ?
      

  9.   

    --测试--测试数据
    create table 表a(a int,b int,c int,d int)
    insert 表a select 1,3,4,5
    union  all select 1,1,4,3
    union  all select 1,2,5,5
    union  all select 1,3,5,5
    union  all select 1,8,3,6
    union  all select 2,1,5,7
    union  all select 2,3,5,6
    union  all select 2,4,4,8
    go--查询
    select a.*
    from 表a a join(
    select b=max(b),b.a,b.c from 表a a join(
    select a,c=max(c) from 表a group by a
    )b on a.a=b.a and a.c=b.c
    group by b.a,b.c
    )b on a.a=b.a and a.b=b.b and a.c=b.c
    go--删除测试
    drop table 表a/*--测试结果
    a           b           c           d           
    ----------- ----------- ----------- ----------- 
    1           3           5           5
    2           3           5           6(所影响的行数为 2 行)
    --*/