|
id name kind info 1 a 23 aaa 2 b 23 bbb 3 c 23 ccc 4 d 24 ddd 5 e 24 eee 6 f 25 fff 7 g 25 ggg sql 语句怎么写才能查询出以下结果集 id name kind info 1 a 23 aaa 4 d 24 ddd 6 f 25 fff 就是每种kind只有一个 好久不写sql了,忘了,还请帮忙 |
|
|
|
select * from table group by kind
|
|
|
select distinct kind from tablename
|
|
|
select distinct kind from tablename
|
|
|
select distinct kind from tablename order by kind
|
|
|
选取多字段:
select distinct kind,id,name,info from tablename |
|
|
都让他们说出来了;(
|
|
|
select * from table group by kind 大哥group by不是这么用的
select distinct kind from tablename select distinct kind from tablename order by kind 这样的话,我的id name info 不是取不出来了 select distinct kind,id,name,info from tablename 你自己试试出来的结果是什么吧 唉,没想到这么个问题还挺麻烦 期待高手 |
|
|
select min(id),name,kind,info from table group by kind,name,info
|
|
|
select a.id,a.name,a.kind,a.info from tablename a where a.id in (select b.id from tablename b where a.kind<>b.kind)
|
|
|
唉,什么都要靠自己
select a.id,a.name,a.kind,a.info from tablename a where a.id in (select top 1 b.id from tablename b where a.kind=b.kind) 搞定 |
|
|
上面写错了
select * from RepeatTable a where a.Rtl_id in (select min(b.Rtl_id) from RepeatTable b where a.Rtl_Tel=b.Rtl_Tel) |
|
|
又写错了,上面是我自已的表,下面才是你的字段名
select * from table a where a.id in (select min(b.id) from table b where a.kind=b.kind) |
|
|
楼上方法也可以, 本来,50分可以全给你,但由于问题我已经自己解决,哪只好大家都分一点,唉,冤啊, 分怎么就不能回收呢
|
|
|
这么多分用来干嘛啊,我对分看得很轻,最重要是别人的认可,就好象你认可我,就算没给我分,我也心甘啊!
|
|