比如说我有张表
Table1
a1 b1 c1Select a1 ,max(c1)as 'c1'
from Table1 
Where a1 = 'aaa'
group by a1我现在需要将以上SQL语句的结果(有可能一行或者多行),比如说得到以下结果:
a1  c1
1   11
2   22
3   33
把以上得到的两个字段用 And 的关系,分别赋给Table1的a1,c1做为条件,查询Table1表,
该SQL语句如何写(不是写存储过程,也不是SQL脚本)?

解决方案 »

  1.   


    select * from table1 a,
    (Select a1 ,max(c1)as 'c1' 
    from Table1 
    Where a1 = 'aaa' 
    group by a1 )b
    where a.a1=b.a1 and 
          a.c1=b.c1
      

  2.   

    select 
      * 
    from 
      Table1
    where 
      a1 
    in
    (select
      a1
    from
    (Select a1 ,max(c1)as 'c1' 
    from Table1 
    Where a1 = 'aaa' 
    group by a1)t)
      

  3.   


    update TableA A set 
    A.字段=b.字段
    from TableB b 
      

  4.   

    猜想楼主是想取a1 = 'aaa' 时,a1重复时取c1最大的那个!select * from table1 t where(select 1 from table1 where t.a1=a1 and t.c1<c1) and
    a1='aaa'
      

  5.   

    [code=SQL]
    select * Table1 where c1=(select max(c1) from Table1 where a1='aaa')
    [code]
    是不是这个,没得好懂得!
    什么是分别赋值哦?
      

  6.   


    Select a1 ,max(c1)as 'c1' 
    from Table1 
    Where a1 = 'aaa' 
    group by a1 可以明确的告诉你,你这样的结果,不可能有多行结果,只有一行,并且a1肯定为‘aaa’