帮帮忙,100分谢

frogshero 2004-07-15 06:15:27
create table bb(a int,c char(10),xx int)
insert bb values(3,'22',234)
insert bb values(3,'33',23)
insert bb values(3,'22',1)
insert bb values(1,'11',5)
insert bb values(1,'11',899)
insert bb values(2,'1',2334)
insert bb values(2,'2',235)
insert bb values(2,'3',156)

查出:
a字段为3,1的记录
就是a字段相同,而c字段不同的个数>1的
即a字段为3,而c字段不同的个数的记录为2
即a字段为2,而c字段不同的个数的记录为3
即a字段为1,而c字段不同的个数的记录为1

...全文
90 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjmym 2004-07-15
  • 打赏
  • 举报
回复
select a,count(distinct c) from bb group by a
pisces007 2004-07-15
  • 打赏
  • 举报
回复
select L.a,L.c,L.xx
from bb L join
(select a,count(distinct c) as i from bb
group by a
) R on L.a=R.a
where R.i>1

--结果
2 1 2334
2 2 235
2 3 156
3 22 1
3 22 234
3 33 23
shirley99 2004-07-15
  • 打赏
  • 举报
回复
select a,count(distinct c) from bb group by a
Frewin 2004-07-15
  • 打赏
  • 举报
回复
看不懂,你将上面的结果输出,看看
WangZWang 2004-07-15
  • 打赏
  • 举报
回复
Select count(distinct c) from bb b where a=1

34,590

社区成员

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

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