数据库
A   B   C   D   E
------------------
1   X   A   1   2
1   X   A   2   9
1   Y   B   3   11
1   Y   B   4   3
1   V   E   5   6
2   N   M   1   7
2   K   L   2   9
3   Y   B   1   1
3   R   T   2   3
3   X   A   3   5
.....
其中B,C是互相对应的即X-A,Y-B, D在A为某一个数时是顺序排列的,
现在要找出当X=1时,B,C唯一的,D最小的记录的字段(B,C,D)
即:
B  C  D
-------
X  A  2
Y  B  11
V  E  6不好意思,没分了

解决方案 »

  1.   

    select c,c,e from tablename a
    where a=1
    and d=(select min(d) from tablename where a=1 and b=a.b)
      

  2.   

    select * from mm aa  where a=1 and not 
    exists(select * from mm bb where a=1 and aa.b=bb.b and aa.c=bb.c and aa.d>bb.d )
      

  3.   


    select B,C,min(D) D
    from 
    (
    select B,C,(D+E) D
    from TableName
    where A=1
    ) B
    group by B,C
      

  4.   

    select b,c,e from tablename a
    where a=1
    and d=(select min(d) from tablename where a=1 and b=a.b)orselect b,c,e from tablename a
    where a=1
    and  not exists (select 1 from tablename where a=1 and b=a.b and d<a.d)
      

  5.   

    select B,C,min(D) as D
    from 
    where A=1
    group by B,C