注册 登录
编程论坛 SQL Server论坛

求解。。多表联查

跳过去 发布于 2013-03-18 17:31, 915 次点击
1、简历表
create table tb_ResumeTxt
(
    ResumeID int primary key identity(1,1),
     UserID int not null,            --外键UserID
)
2、招聘表
create table tb_RecruiTxt
(
    RecruiTxtID int primary key identity(1,1),
    ZhaopinTitle varchar(200) not null,
    UserID  int not null

3、投递简历/公司向用户发送邀请
create table tb_UserDeliver
(
    DeliverID int primary key identity(1,1),
    RecruiTxtID int not null,--外键(recruiTxtID) 招聘简历信息ID
    ResumeID int not null ,  --外键(resumeID)  求职者简历ID
    Isyaoqiu int default(0) check(Isyaoqiu=0 or Isyaoqiu=1),  --企业是否邀请
    DeliverTime datetime default(getdate()) --系统当前时间
)

根据 用户 简历ID来 查看 我投过 哪家公司,
根据 招聘ID 来查看我邀请过哪些用户
这种SQL语句怎么写啊?急求啊。。。。会的帮帮忙

6 回复
#2
跳过去2013-03-18 21:10
没人会吗
#3
Aviva_Wang2013-03-21 15:55
本来想写写的,可是,我们办公室的人吵死了,我也静不下来的,这个还是蛮经典的子查询的例子,请问写完了吗?写完的话,贴过来让我看看和我写的是否一样吧。我最近在写数据库的东西,想多练习练习
#4
Aviva_Wang2013-03-22 08:23
--根据 用户 简历ID来 查看 我投过 哪家公司
select * from UserDliver u
inner join ResumeTxt r on u.ResumeID =r.ResumeID
inner join RecruiTxt t on r.UserID =t.UserID
where r.UserID =@UserID

-- 根据 招聘ID 来查看我邀请过哪些用户

select * from  ResumeTxt  r
inner join RecruiTxt t  on r.UserID =t.UserID
inner join UserDeliver u on u.RecruiTxtID = t.RecruiTxtID
where u.RecruiTxtID=@RecruiTxtID      
不知道对不对,请版主指教                           
#5
Aviva_Wang2013-03-22 08:53
--子查询根据 用户 简历ID来 查看 我投过 哪家公司
select DeliverID from UserDeliver u
where u.RecruiTxtID = (select RecruiTxtID from RecruiTxt r where r.userId =@UserID)
下面的一个语句也类似
#6
跳过去2013-07-05 16:31
我参与过的帖子
create proc proc_post_UserISPost
@userID int
as
select Post.PostID,Post.PostTypeID,Post.PostTitle,Post.PostTime from  ((select distinct PostComment.PostID
from PostComment JOIN
     CommentReply on PostComment.UserID=@userID or CommentReply.UserID =@userID
where PostComment.UserID=@userID  or
      CommentReply.UserID=@userID) as t1
left join Post on t1.PostID = Post.PostID)
go
#7
yjon20122013-07-10 09:27
都是高人啊!
1