求一简单的sql语句

YAMABACK 2004-10-21 09:35:00
一个表有a,b,c,d,e五个字段,a是关键字,但是想得到b,c组合的唯一的记录,例如:

1,21,22,40,50
2,21,22,49,40
3,21,20,33,40
4,22,30,55,52
……………………

希望得到第1,2条记录
...全文
104 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
chd2001 2004-10-21
  • 打赏
  • 举报
回复
这个语句才能得到标准答案:
select a,b,c,d,e from TableName1 join (
select min(a) f from TableName1 group by b,c) TableName2
on TableName13.a=TableName2.f
chd2001 2004-10-21
  • 打赏
  • 举报
回复
select min(a) a,b,c from TableName group by b,c order by a
mulitao521 2004-10-21
  • 打赏
  • 举报
回复
select distinct b,c from table
LJWS 2004-10-21
  • 打赏
  • 举报
回复
select * from [table] a join (
select b,c,min(id) as id from [table] group by b,c) b
on a.id=b.id
YAMABACK 2004-10-21
  • 打赏
  • 举报
回复
抱歉,是想得到第1,3,4条记录

mgsray 2004-10-21
  • 打赏
  • 举报
回复
select * from table ta,(select b, c from table group by b,c having count(1)>1) tb
where ta.b=tb.b and ta.c=tb.c
xuam 2004-10-21
  • 打赏
  • 举报
回复
select * from tablename where exists (select cast(b as char)+cast(c as char) from tablename having count(cast(b as char)+cast(c as char))>1)
hsh_boy 2004-10-21
  • 打赏
  • 举报
回复
说明白一点,把你要的结果打出来
kookboy 2004-10-21
  • 打赏
  • 举报
回复
上面是不唯一的,下面是唯一的
select distinct A.* from tablename A,tablename A
where (A.b <> B.b or A.c <> B.c) and A.a <> B.a
kookboy 2004-10-21
  • 打赏
  • 举报
回复
是唯一还是不唯一呀,楼主
select distinct A.* from tablename A,tablename A
where A.b = B.b and A.c = B.c and A.a <> B.a
LJWS 2004-10-21
  • 打赏
  • 举报
回复
不明白你的意思

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧