这样的SQL语句怎样写:在线等待

lixp 2003-08-22 09:31:45
我的表中有 id,spid,spmc字段,如何判断一个spid对应了两个spmc;记录格式如下:
----------------------------------------------------------
id spid spmc
1 001 A
2 002 B
3 001 A1
4 003 C
5 001 A1

--------------------------------------------------------------
我要找出001这类 spid
...全文
53 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lixp 2003-08-22
  • 打赏
  • 举报
回复
谢谢
zjhclf 2003-08-22
  • 打赏
  • 举报
回复
select a.id from hv_yqxf a,hv_yqxf b where a.spid=b.spid and
a.spmc<>b.spmc;
huangxinru 2003-08-22
  • 打赏
  • 举报
回复
Select spid,spmc,count(spid) From hv_ygxf where xfyf ='2003-08' and xfd ='11'
group by spid,spmc
having count(spid)>1
lixp 2003-08-22
  • 打赏
  • 举报
回复
都不对,记录有上万条,每组spid,spmc 经过count后,都会>1 ;问题是如何选出像001同一个编码有两个名称与之对应。急呀
huangxinru 2003-08-22
  • 打赏
  • 举报
回复
select spid,count(spid)
from table
group by spid
having count(spid)>1
lixp 2003-08-22
  • 打赏
  • 举报
回复
记录有上万条
我自己写如下:
Select distinct spid,spmc From hv_ygxf where xfyf ='2003-08' and xfd ='11'
group by spid,spmc
having count(spid)>1
得到结果总好像不对呀
polugen 2003-08-22
  • 打赏
  • 举报
回复
select spid from tname gorup by spid having count(1)=2

752

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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