菜鸟紧急求助一个SQL语句,望各位大侠不吝赐教!!

Xiao_Ma123456789 2016-08-10 11:11:52
select code from wms where id='1'

code的值为多个。
如:001
001
001
002
目的:如果查出的值存在不一样的,就查个1出来,求语句怎么写。select 1 from wms where id=‘1’ and .........
...全文
171 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ghx287524027 2016-08-10
  • 打赏
  • 举报
回复
select case when count(distinct  code)>1 then 1 else 0 end flag from wms where id='1'
js14982 2016-08-10
  • 打赏
  • 举报
回复

select case when cnt>1 then 1 else 0 end is_error 
from
(select count(distinct code) cnt from wms where id='1') t
;
卖水果的net 2016-08-10
  • 打赏
  • 举报
回复

-- 换这个吧
select case when count(*) > 1 then 1 else 0 end  from wms where id='1'
Xiao_Ma123456789 2016-08-10
  • 打赏
  • 举报
回复
引用 1 楼 wmxcn2000 的回复:
select distinct code from wms where id='1'
大侠我知道distinct过滤啊,你可能没明白我的意思,我从新说一下啊。我想从wms这张表中查出code,id是传过来的,一个id对应多个code,如果查出的这些code中存在不一样的值,就返回一个flag,所以我用select 1 from wms 这种写法。当flag等于1时我会抛出一个异常。求语句怎么写
卖水果的net 2016-08-10
  • 打赏
  • 举报
回复
select distinct code from wms where id='1'

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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