或 C1 C2 C3 C4 ----- --------- ------ ---------- 11 88 1000 886 12 100 1000 889有主键能做么 c1为主健没主键 又如何 这是我写的 select max(c1), a.c2, a.c3 from a, (select c2,max(c3) as c3 from a group by c2) b where a.c2 = b.c2 and a.c3 = b.c3 group by a.c2, a.c3; 能满足要求 不过太复杂了那位兄弟能找一个简单点的方法
select a.c1,a.c2,a.c3,a.c4 from table a where (a.c2,a.c3) = (select max(a.c3) from table b where b.c1 = a.c1 group by b.c2) group by a.c2
对不起上面错了 select a.c1,a.c2,a.c3,a.c4 from table a where (a.c2,a.c3) = (select b.c2,max(b.c3) from table b where b.c1 = a.c1 group by b.c2) group by a.c2
where c3 in(select max(c3) from a group by c2)
select c1,c2,c4 from a
where c3 in(select max(c3) from a group by c2)
select a.c1,a.c2,a.c3
from tbl a,(select c2,max(c3) c3 from tbl group by c2) b
where a.c2 = b.c2 and a.c3 = b.c3
where (c2,c3) in (select c2,max(c3) from a group by c2)
c1 c2 c3 c410 100 1000 888
11 88 1000 886
9 100 888 885
8 100 1000 885
12 100 1000 889根据c2分组 得到c3为最大的随便一条纪录的全集
需求很简单 好像语句不怎么简单select c2,max(c3) as c3 from a group by c2; C2 C3
----- ----------
88 1000
100 1000怎么能得到c3的这条纪录的c1,c4 我想要的结果
C1 C2 C3 C4
----- --------- ------ ----------
11 88 1000 886
10 100 1000 888
或 C1 C2 C3 C4
----- --------- ------ ----------
11 88 1000 886
8 100 1000 885
或
C1 C2 C3 C4
----- --------- ------ ----------
11 88 1000 886
12 100 1000 889有主键能做么 c1为主健没主键 又如何
这是我写的
select max(c1), a.c2, a.c3 from a, (select c2,max(c3) as c3 from a group by c2) b where a.c2 = b.c2 and a.c3 = b.c3 group by a.c2, a.c3;
能满足要求
不过太复杂了那位兄弟能找一个简单点的方法
where (a.c2,a.c3) = (select max(a.c3) from table b where b.c1 = a.c1 group by b.c2)
group by a.c2
select a.c1,a.c2,a.c3,a.c4 from table a
where (a.c2,a.c3) = (select b.c2,max(b.c3) from table b where b.c1 = a.c1 group by b.c2)
group by a.c2