社区
MS-SQL Server
帖子详情
急~~~~~~~~~~~~~在线等待 SQL
changkai
2003-12-19 09:06:31
两个表
表名: 表A 表B
列名: 药品名称 药品通用名 标号
表的内容: 阿莫西林 阿莫西林胶囊
阿莫西林***
....... ........
要求:
表B中的药品通用名 有跟表A的药品名称相似的都找出来,有相似的在标号那一列写
上1,没相似的在标号那一列写上0
...全文
50
20
打赏
收藏
急~~~~~~~~~~~~~在线等待 SQL
两个表 表名: 表A 表B 列名: 药品名称 药品通用名 标号 表的内容: 阿莫西林 阿莫西林胶囊 阿莫西林*** ....... ........ 要求: 表B中的药品通用名 有跟表A的药品名称相似的都找出来,有相似的在标号那一列写 上1,没相似的在标号那一列写上0
复制链接
扫一扫
分享
转发到动态
举报
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
Oracle启动管理命令
- **
SQL
*Plus启动**:登录到数据库服务器,以管理员身份运行
SQL
*Plus,输入`startup mount`命令装载数据库,然后输入`alter database open`打开数据库。如果需要进行实例恢复,可以使用`startup force`命令。 - *...
SQL
Server 2017 Developer的下载、安装、配置【以及SSMS的下载安装配置】以及数据库表的基本操作
开学要学数据库,老师说要使用
SQL
Sever,需要自己安装,于是就有了它。 老师建议我们下载这个,因为它,免费!!! ** 下载 ** 下载地址:[
SQL
Server] 加载时间略长,请耐心
等待
。加载完成后,找到上图,下载,...
SQL
Server 数据库安装教程
SQL
Server 2017
1,官网下载
SQL
Server 2017 评估版(试用180天)或免费版。 官网:
SQL
Server 下载 | Microsoft 软件版本看你自己需求啦,反正我是下了
SQL
Server 2017 评估版(试用180天,秘钥自己百度) 下载后,软件有点小,...
ORACLE 用DBLINK连接
SQL
SERVER出现锁
等待
超时 求解决。
ORACLE用DBLINK连接
SQL
SERVER查询数据,前段时间用的好好的,没问题。 今天就出现用PL/
SQL
DEVELOPER查询。结果出不来,一直在执行。 诡异的是把在执行的语句中止掉,然后在查,就很快出结果了。 郁闷啊。求各位...
简单英译汉
SQL
脚本
create table t_dictionary(word varchar(200), trans varchar(1000)); insert into t_dictionary values('abandon','v.抛弃,放弃'); insert into t_dictionary values('abandonment','n.... insert into t_...
MS-SQL Server
34,838
社区成员
254,632
社区内容
发帖
与我相关
我的任务
MS-SQL Server
MS-SQL Server相关内容讨论专区
复制链接
扫一扫
分享
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章