日期:2014-05-17  浏览次数:20533 次

数据库问题,请各位高手解答!急!!!
数据库中有两个表,一个是resource,另一个是resinterview,他们都有字段email,我想将email相同的resinterview中的resinterviewId导入到resource表中的InterviewId字段中。注意,email有相同的也有不同的,需要将email相同的数据查出来。请问各位高手怎么写sql语句?

------解决方案--------------------
SQL code
INSERT INTO resource
            (interviewId)
VALUES      (SELECT resinterviewId
             FROM   resinterview
             WHERE  email IN (SELECT email
                              FROM   resinterview
                              GROUP  BY email
                              HAVING Count(email) >= 2))

------解决方案--------------------
SQL code
--resource表
select t.[email] from
(
select [email],count(*) cnt from [resource]
group by [email]
) t
where t.[cnt]>1
----------------------
--resinterview表
select t.[email] from
(
select [email],count(*) cnt from [resinterview]
group by [email]
) t
where t.[cnt]>1