两表比较的语句怎么写

dzogchen 2006-11-29 11:22:13
A表中有个字段 A_NAME 其中有单位名称100个(可能有重复名称)
B表中有个字段 B_NAME 其中有单位名称30个(没有重复名称)
要求:
1 比对A_NAME & B_NAME 将A_NAME 没有的插入B_NAME;
2 如果A_NAME有重复的 在B_count中加数据

A_NAME
张三
李四
王二麻
张三

B_NAME
李四
王二麻

处理后是B表是======>

B_NAME B_count
李四
王二麻
张三 2
...全文
197 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
dzogchen 2006-11-30
  • 打赏
  • 举报
回复
这个是我ORACLE语法的 请问怎么修改成MYSQL
create or replace procedure process1
is
cursor cur_title is select tid,title from t_maps_hot
where title not in (select com_name from t_yp_thread);
m_tid varchar(200);
m_title varchar(200);
m_content varchar(200);
hot_id varchar(200);
num_id number;
begin
open cur_user;
loop
fetch cur_user into m_tid,m_title;
exit when cur_user%NOTFOUND;
begin
m_content:='|';
select count(*) into num_id from t_yp_thread where com_name=m_title;
if num_id=0 then
m_content:=m_content+m_tid+'|';
else
begin
select maps_hot_id into hot_id from t_yp_thread where com_name=m_title;
m_content:=hot_id+'|'+m_tid+'|';
end;
end if;
insert into t_yp_thread(maps_hot_id,com_name,im) values(m_content,m_title,m_title);
commit;
end;
end loop;
close cur_user;
end;
/
huailairen 2006-11-29
  • 打赏
  • 举报
回复
insert into B(B_NAME , B_count)
select A_NAME ,count(*)
from A
group by A_NAME
where A_NAME not in (select B_NAME from B);
dzogchen 2006-11-29
  • 打赏
  • 举报
回复
谁能给个存储过程遍历表的例子
dzogchen 2006-11-29
  • 打赏
  • 举报
回复
楼上 可能是我为了表达方便才说COUNT()的 事实上我要在B_COUNT出现的是|1||2|

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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