SELECT A0,MIN(A1) AS A1 FROM A GROUP BY A0 ORDER BY A0
CSDNM(决定不当CSDN经理了) 的做法完全正确啊!
field A0 A1 A2 A3 value 0 x a h 0 2 b i 0 3 c j 1 y d k 1 2 e l 1 3 f m 2 z g n Query Result A0 A1 A2 A3 0 x a h 1 y d k 2 z g n 就是A0相同的只取一个!和其他的字段没有关系,
select distinct A0 ,'' as A1 ,'' as A2,''as A3 into ##yTable from Aupdate ##yTable set A1=A.A1 ,A2=A.A2,A3=A.A3 from A where ##yTable.A0=A.A0select * from ##yTabledrop table ##yTable
SELECT A0,A1, A2, A3 FROM A GROUP BY A0 ORDER BY A0
如果没有主键只能这样做select identity(int,1,1) as id,* into #tmp from yourtable select a0,a1,a2,a3 from #tmp where id in (select max(id) from #tmp group by a0)
select * from myTable, (select min(rowid) as id from myTable group by A0) c where myTable.rowid =id这样做有没有什么问题!
rowid唯一就没有问题select * from myTable, (select min(rowid) as id from myTable group by A0) c where myTable.rowid =c.id
是的,如果2个表union,这时候的rowid,怎么求。
select distinct A0 ,'' as A1 ,'' as A2,''as A3 from a
给你个例子,其实把你的表结构弄上来就好解决了select min(x) from (select rowid as x ,rain.test_1.* from rain.test_1 union select rowid as x ,test.test.* from test.test) z group by z.a;
GROUP BY A0
ORDER BY A0
value 0 x a h
0 2 b i
0 3 c j
1 y d k
1 2 e l
1 3 f m
2 z g n
Query Result
A0 A1 A2 A3
0 x a h
1 y d k
2 z g n
就是A0相同的只取一个!和其他的字段没有关系,
into ##yTable from Aupdate ##yTable set A1=A.A1 ,A2=A.A2,A3=A.A3
from A where ##yTable.A0=A.A0select * from ##yTabledrop table ##yTable
GROUP BY A0
ORDER BY A0
有没有一句sql就可以
select a0,a1,a2,a3 from #tmp where id in (select max(id) from #tmp group by a0)
select rowid as x ,test.test.* from test.test) z group by z.a;