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

解决方案 »

  1.   

    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);
      

  2.   

    楼上 可能是我为了表达方便才说COUNT()的  事实上我要在B_COUNT出现的是|1||2|
      

  3.   

    这个是我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;
    /