我有一个表ID content
1 a
2 a
3 a
4 b
5 b
6 c
7 c我要怎样才能得到ID content
1 a
4 b
6 c 这样的结果(保留与a、b、c相应的ID最小的那个值)?若用select distinct则只能压缩content列,不能提取与content相应的ID列的最小值望帮忙,先此谢过
1 a
2 a
3 a
4 b
5 b
6 c
7 c我要怎样才能得到ID content
1 a
4 b
6 c 这样的结果(保留与a、b、c相应的ID最小的那个值)?若用select distinct则只能压缩content列,不能提取与content相应的ID列的最小值望帮忙,先此谢过
from table1
group by content
或者
select id,content from table a where not exists(select 1 from table b where a.content=b.content and a.id>b.id)
select 1, 'a' union
select 2, 'a' union
select 3, 'a' union
select 4, 'b' union
select 5, 'b' union
select 6, 'c' union
select 7, 'c'select content , min(id) as c
from @t a
group by content
order by c
aa
Aa
aa
b
B
c
c通过一种办法变为content
aa
Aa
b
B
c呢? 再次感谢楼上两位兄台
1 aa
2 Aa
3 aa
4 b
5 B
6 c
7 c如何在区分大小写的情况下压缩content列,并取得相应的最小的ID值,生成下表ID content
1 aa
2 Aa
4 b
5 B
6 c问题2:根据字符进行的join连接好像也不区分大小写,怎么从根本上解决SQL根据字符进行查询时不区分大小字符的问题。再次劳驾各位大虾伸出援手,非常感谢
from @t
group by content collate Chinese_PRC_CS_AS_WS
from @t
group by content collate Chinese_PRC_CS_AS_WS