求一查询语句

renwox88 2006-02-24 10:02:00
有一组号码,比如
1234A
1234B
f8976A
f8976B
98987777A
dafdj98B
98978787
f099788
要求要查询到末尾数字单独为A和B的记录,像1234A,1234B成对出现就要,而98987777A单独出现A的这种情况就需要,dafdj98B末尾单独为B的数据也需要,请各位朋友帮下忙

...全文
124 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
renwox88 2006-02-24
  • 打赏
  • 举报
回复
我写错啦,要求要查询dhhm末尾数字单独为A和B的记录,像1234A,1234B成对出现就不要,我表中成对出现的意思就是末尾数为A、B而A、b前面的数字都是相同的,像f8976A,f8976B也是不要的。而98987777A单独出现A的这种情况就需要,dafdj98B末尾单独为B的数据也需要,请各位朋友帮下忙,数据中成对成对出现的不要。我写错啦,sbaz朋友你帮看看
renwox88 2006-02-24
  • 打赏
  • 举报
回复
我写错啦,要求要查询dhhm末尾数字单独为A和B的记录,像1234A,1234B成对出现就不要,而98987777A单独出现A的这种情况就需要,dafdj98B末尾单独为B的数据也需要,请各位朋友帮下忙,数据中成对成对出现的不要。我写错啦,sbaz朋友你帮看看
zlz_212 2006-02-24
  • 打赏
  • 举报
回复
select num from tablename
where substr(num,-1) in('A','B')
超叔csdn 2006-02-24
  • 打赏
  • 举报
回复
拷错了.
select num from tablename
where substr(num,-1)='A'
or substr(num,-1)='B'
超叔csdn 2006-02-24
  • 打赏
  • 举报
回复
select num from tablename
where substr(a.num,-1)='A'
or substr(b.num,-1)='B'
你说都要的话.就这样!
renwox88 2006-02-24
  • 打赏
  • 举报
回复
有一组号码,表为test,字段dhhm数据比如如下:
1234A
1234B
f8976A
f8976B
98987777A
dafdj98B
98978787
f099788
要求要查询dhhm末尾数字单独为A和B的记录,像1234A,1234B成对出现就要,而98987777A单独出现A的这种情况就需要,dafdj98B末尾单独为B的数据也需要,请各位朋友帮下忙

renwox88 2006-02-24
  • 打赏
  • 举报
回复
这个问题我解决了,谢谢各位的帮助啊,用次语句可解决啦select shuju from pyk a
where (substr(shuju,-1,1)='B'
and not exists(select 1 from pyk where shuju = (substr(a.shuju,1,length(a.shuju) - 1)||'A')))
or
(substr(shuju,-1,1)='A'
and not exists(select 1 from pyk where shuju = (substr(a.shuju,1,length(a.shuju) - 1)||'B')));
SQL> create table pyk(shuju varchar2(20));

Table created


SQL> insert into pyk values('987866A');

1 row inserted

SQL> insert into pyk values('987866B');

1 row inserted

SQL> insert into pyk values('7866B');

1 row inserted

SQL> insert into pyk values('786A');

1 row inserted

SQL> insert into pyk values('99999999');

1 row inserted

SQL> insert into pyk values('99999999A');

1 row inserted

SQL> insert into pyk values('99999999B');

1 row inserted

SQL> commit;
表pyk的数据为:
987866A
987866B
7866B
786A
99999999
99999999A
99999999B
执行后的结果为:
7866B
786A
谢谢各位的帮助

renwox88 2006-02-24
  • 打赏
  • 举报
回复
boydgmx你好,你这里的from tlb b
是怎么得来的?tbl a是我本身的表,b是怎么构建出来的?
boydgmx 2006-02-24
  • 打赏
  • 举报
回复
select *
from tbl a
where substr(a.dhhm,-1) in('A','B')
and not exists(
select 0
from tlb b
where substr(b.dhhm,1,length(b.dhhm)-1) = substr(a.dhhm,1,length(a.dhhm)-1)
);

17,134

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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