急~~~~~~~~~~~~~在线等待 SQL

changkai 2003-12-19 09:06:31
两个表
表名: 表A 表B
列名: 药品名称 药品通用名 标号

表的内容: 阿莫西林 阿莫西林胶囊
阿莫西林***
....... ........

要求:

表B中的药品通用名 有跟表A的药品名称相似的都找出来,有相似的在标号那一列写
上1,没相似的在标号那一列写上0
...全文
50 20 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
changkai 2003-12-22
  • 打赏
  • 举报
回复
谢谢各位了~!
changkai 2003-12-19
  • 打赏
  • 举报
回复
我就用你这个
update 表B set 标号=1
from 表B b join 表A a on b.药品通用名 like '%'+a.药品名称+'%'

10分钟都不行,我停了
zjcxc 元老 2003-12-19
  • 打赏
  • 举报
回复
你是用那个语句?
changkai 2003-12-19
  • 打赏
  • 举报
回复
好象速度很慢,更新不了
我每个表也才5000条记录
运行了5分钟都运行不了
yangvxin1 2003-12-19
  • 打赏
  • 举报
回复
update 表B set 标号=1
from 表A a where charindex(a.药品名称,b.药品通用名)>0

dlpseeyou 2003-12-19
  • 打赏
  • 举报
回复
update 表B b case when a.药品名称 is null then 0 else 1 end left join 表A a where path(a.药品名称,b.药品通用名)>0
pengdali 2003-12-19
  • 打赏
  • 举报
回复
测试2:

create table b (药品通用名 varchar(20),标号 bit)
insert b (药品通用名) select '阿莫西林胶囊' union select '阿莫西林***' union select 'aaaa'

create table a (药品名称 varchar(20))
insert a select '阿莫西林'





update b set 标号=case when a.药品名称 is null then 0 else 1 end from b left join a on b.药品通用名 like '%'+a.药品名称+'%'

select * from b



/*

药品通用名 标号
-------------------- ----
aaaa 0
阿莫西林*** 1
阿莫西林胶囊 1

(所影响的行数为 3 行)
*/
zjcxc 元老 2003-12-19
  • 打赏
  • 举报
回复
--下面是测试
declare @表A table(药品名称 varchar(10))
insert into @表A
select '阿莫西林'

declare @表B table(药品通用名 varchar(50),标号 bit)
insert into @表B(药品通用名)
select '阿莫西林胶囊'
union all select '阿莫西林***'
union all select '比历史最高水平'

--更新处理
update @表B set 标号=1
from @表B b join @表A a on b.药品通用名 like '%'+a.药品名称+'%'

--显示处理结果
select * from @表B

/*--测试结果
药品通用名 标号
-------------------------------------------------- ----
阿莫西林胶囊 1
阿莫西林*** 1
比历史最高水平 NULL

(所影响的行数为 3 行)
--*/
pengdali 2003-12-19
  • 打赏
  • 举报
回复
测试:

create table b (药品通用名 varchar(20),标号 bit)
insert b (药品通用名) select '阿莫西林胶囊' union select '阿莫西林***' union select 'aaaa'

create table a (药品名称 varchar(20))
insert a select '阿莫西林'



update b set 标号=case when exists(select 1 from a where b.药品通用名 like '%'+a.药品名称+'%') then 1 else 0 end


/*

药品通用名 标号
-------------------- ----
aaaa 0
阿莫西林*** 1
阿莫西林胶囊 1

(所影响的行数为 3 行)
*/
changkai 2003-12-19
  • 打赏
  • 举报
回复
我先式一下
:)
changkai 2003-12-19
  • 打赏
  • 举报
回复
谢谢各位大哥
zjcxc 元老 2003-12-19
  • 打赏
  • 举报
回复
update 表B set 标号=1
from 表B b join 表A a on b.药品通用名 like '%'+a.药品名称+'%'
pengdali 2003-12-19
  • 打赏
  • 举报
回复
如果是update:



update b set 标号=case when exists(select 1 from a where b.药品通用名 like '%'+a.药品名称+'%') then 1 else 0 end

或:

update b set 标号=case when a.药品名称 is null then 0 else 1 end from b left join a on b.药品通用名 like '%'+a.药品名称+'%'
dlpseeyou 2003-12-19
  • 打赏
  • 举报
回复
update 表B b set 标号=1 right join 表A a where path(a.药品名称,b.药品通用名)>0
pengdali 2003-12-19
  • 打赏
  • 举报
回复
或:

select b.*,case when a.药品名称 is null then 0 else 1 end 标号 from b left join a on b.药品通用名 like '%'+a.药品名称+'%'
pengdali 2003-12-19
  • 打赏
  • 举报
回复
select *,case when exists(select 1 from a where b.药品通用名 like '%'+a.药品名称+'%') then 1 else 0 end from b
changkai 2003-12-19
  • 打赏
  • 举报
回复
高手帮忙
LoveSQL 2003-12-19
  • 打赏
  • 举报
回复
测试结果
药品通用名 标号
-------------------- ----
aaaa 0
阿莫西林*** 1
阿莫西林?? 1

(3 row(s) affected)
zjcxc 元老 2003-12-19
  • 打赏
  • 举报
回复
--那你试试用这个:

update 表B set 标号=1
from 表B a
where exists(select 1 from 表A where a.药品通用名 like '%'+药品名称+'%')
LoveSQL 2003-12-19
  • 打赏
  • 举报
回复
create table b (药品通用名 varchar(20),标号 bit)
insert b (药品通用名) select '阿莫西林胶囊' union select '阿莫西林***' union select 'aaaa'

create table a (药品名称 varchar(20))
insert a select '阿莫西林'


update b
set b.标号=case when charindex(a.药品名称,b.药品通用名)>0 then 1 else 0 end from b b,a a

34,838

社区成员

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

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