1 select * from company inner join companyjob on company.id =companyjob.pid inner join workarea on workarea.wid=companyjob.pid inner join workganwei on workganwei.gid=companyjob.id where workarea.省份='湖北'3 select * from company inner join companyjob on company.id =companyjob.pid inner join workarea on workarea.wid=companyjob.pid inner join workganwei on workganwei.gid=companyjob.id where companyjob.职位='网络工程师'其余的自己应该会写了吧
--写个存储过程查询就可以了 create proc p_qry @省份 nvarchar(50)=null, @城市 nvarchar(50)=null, @岗位类别 nvarchar(50)=null, @具体岗位 nvarchar(50)=null as select * from company a,companyjob b,workarea c,worksangwei d where a.id=b.pid and b.id=c.wid and c.id=d.gid and (c.省份=@省份 or @省份=null) and (c.城市=@城市 or @城市=null) and (d.岗位类别=@岗位类别 or @岗位类别=null) and (d.具体岗位=@具体岗位 or @具体岗位=null) go--查询示例--1 如果用户选择了省份和城市都不限制,那么就不论工作地区在哪里,职位都能选择出来, exec p_qry --如果用户选择了省份是湖北,那么就搜索所有省份是湖北的记录,包括湖北-武汉,湖北-孝感,湖北-黄石.... exec p_qry @省份='湖北'--如果选择了省份是湖北,城市是武汉,那么只搜索湖北-武汉的记录 exec p_qry @省份='湖北',@城市='武汉'
create proc search @province nvarchar(50)=NULL,--省份 @city nvarchar(50)=NULL, --城市 @posttype nvarchar(50)=NULL,--岗位类别 @concretely nvarchar(50)=NULL--具体岗位 as select * from company a,companyjob b,workarea c,worksangwei d where a.id=b.pid and b.id=c.wid and c.id=d.gid and (c.省份=@province or @province =NULL) and (c.城市=@city or @city=NULL) and (d.岗位类别=@posttype or @posttype=NULL) and (d.具体岗位=@concretely or @concretely=NULL) go這個學個存儲過程就可以
create proc p_qry @省份 nvarchar(50)=null, @城市 nvarchar(50)=null, @岗位类别 nvarchar(50)=null, @具体岗位 nvarchar(50)=null as select DISTINCT * --使用distinct就可以了 from company a,companyjob b,workarea c,worksangwei d where a.id=b.pid and b.id=c.wid and c.id=d.gid and (c.省份=@省份 or @省份=null) and (c.城市=@城市 or @城市=null) and (d.岗位类别=@岗位类别 or @岗位类别=null) and (d.具体岗位=@具体岗位 or @具体岗位=null) go
zjcxc(邹建)比较麻烦的问题啊,用distinct不行,关键是 select DISTINCT * --使用distinct就可以了 from company a,companyjob b,workarea c,worksangwei d where a.id=b.pid and b.id=c.wid and b.id=d.gid ///这里是b和d相关联的 and (c.省份=@省份 or @省份=null) and (c.城市=@城市 or @城市=null) and (d.岗位类别=@岗位类别 or @岗位类别=null) and (d.具体岗位=@具体岗位 or @具体岗位=null) 这么写的话会出来这样的记录 江苏省 南京市 3 16 石油化工类 石油化工类-不限 测试工程师 北京市 不限 4 17 石油工程类 石油工程类-不限 网络工程师 浙江省 杭州市 4 17 石油工程类 石油工程类-不限 网络工程师 北京市 不限 5 17 计算机业(IT)类 计算机业(IT)类 网络工程师 浙江省 杭州市 5 17 计算机业(IT)类 计算机业(IT)类 网络工程师 上海市 不限 6 18 计算机业(IT)类 数据库开发 地址工程师 福建省 福州市 6 18 计算机业(IT)类 数据库开发 地址工程师 上海市 不限 7 18 石油地质类 石油地质类-不限 地址工程师 福建省 福州市 7 18 石油地质类 石油地质类-不限 地址工程师 上海市 不限 8 18 石油储运类 石油储运类-不限 地址工程师 福建省 福州市 8 18 石油储运类 石油储运类-不限 地址工程师象”地址工程师“为什么会出来6个呢,是因为对于地址工程师这条记录来说,有2个工作地区,”上海市-不限"和“福建省-福州市“,而所属的工作岗位有3个,所以出来的就是6个这样的记录,这6个是分别不相同,所以distinct是不行的啊
select * from
company inner join companyjob on company.id =companyjob.pid
inner join workarea on workarea.wid=companyjob.pid
inner join workganwei on workganwei.gid=companyjob.id where workarea.省份='湖北'3
select * from
company inner join companyjob on company.id =companyjob.pid
inner join workarea on workarea.wid=companyjob.pid
inner join workganwei on workganwei.gid=companyjob.id where companyjob.职位='网络工程师'其余的自己应该会写了吧
create proc p_qry
@省份 nvarchar(50)=null,
@城市 nvarchar(50)=null,
@岗位类别 nvarchar(50)=null,
@具体岗位 nvarchar(50)=null
as
select *
from company a,companyjob b,workarea c,worksangwei d
where a.id=b.pid
and b.id=c.wid
and c.id=d.gid
and (c.省份=@省份 or @省份=null)
and (c.城市=@城市 or @城市=null)
and (d.岗位类别=@岗位类别 or @岗位类别=null)
and (d.具体岗位=@具体岗位 or @具体岗位=null)
go--查询示例--1 如果用户选择了省份和城市都不限制,那么就不论工作地区在哪里,职位都能选择出来,
exec p_qry --如果用户选择了省份是湖北,那么就搜索所有省份是湖北的记录,包括湖北-武汉,湖北-孝感,湖北-黄石....
exec p_qry @省份='湖北'--如果选择了省份是湖北,城市是武汉,那么只搜索湖北-武汉的记录
exec p_qry @省份='湖北',@城市='武汉'
@province nvarchar(50)=NULL,--省份
@city nvarchar(50)=NULL, --城市
@posttype nvarchar(50)=NULL,--岗位类别
@concretely nvarchar(50)=NULL--具体岗位
as
select *
from company a,companyjob b,workarea c,worksangwei d
where a.id=b.pid
and b.id=c.wid
and c.id=d.gid
and (c.省份=@province or @province =NULL)
and (c.城市=@city or @city=NULL)
and (d.岗位类别=@posttype or @posttype=NULL)
and (d.具体岗位=@concretely or @concretely=NULL)
go這個學個存儲過程就可以
保证“东软股份”这个公司的发布的职位“网络工程师”这条记录只显示一条,不是显示N条,现在我exec p_qry 后,选择出来是这样的31 16 江苏省 南京市 3 16 石油化工类 石油化工类-不限 13 超级设计联盟 13 测试工程师
32 17 北京市 不限 4 17 石油工程类 石油工程类-不限 13 超级设计联盟 13 网络工程师
33 17 浙江省 杭州市 4 17 石油工程类 石油工程类-不限 13 超级设计联盟 13 网络工程师
32 17 北京市 不限 5 17 计算机业(IT)类 计算机业(IT)类-不限 13 超级设计联盟 13 网络工程师
33 17 浙江省 杭州市 5 17 计算机业(IT)类 计算机业(IT)类-不限 13 超级设计联盟 13 网络工程师
34 18 上海市 不限 6 18 计算机业(IT)类 数据库开发与管理(DBA) 13 超级设计联盟 13 地址工程师
35 18 福建省 福州市 6 18 计算机业(IT)类 数据库开发与管理(DBA) 13 超级设计联盟 13 地址工程师
34 18 上海市 不限 7 18 石油地质类 石油地质类-不限 13 超级设计联盟 13 地址工程师
35 18 福建省 福州市 7 18 石油地质类 石油地质类-不限 13 超级设计联盟 13 地址工程师
34 18 上海市 不限 8 18 石油储运类 石油储运类-不限 13 超级设计联盟 13 地址工程师
35 18 福建省 福州市 8 18 石油储运类 石油储运类-不限 13 超级设计联盟 13 地址工程师
这些职位都重复了,如果是重复的,比如地址工程师,只显示其中一条就行了,怎么修改?
@省份 nvarchar(50)=null,
@城市 nvarchar(50)=null,
@岗位类别 nvarchar(50)=null,
@具体岗位 nvarchar(50)=null
as
select DISTINCT * --使用distinct就可以了
from company a,companyjob b,workarea c,worksangwei d
where a.id=b.pid
and b.id=c.wid
and c.id=d.gid
and (c.省份=@省份 or @省份=null)
and (c.城市=@城市 or @城市=null)
and (d.岗位类别=@岗位类别 or @岗位类别=null)
and (d.具体岗位=@具体岗位 or @具体岗位=null)
go
select DISTINCT * --使用distinct就可以了
from company a,companyjob b,workarea c,worksangwei d
where a.id=b.pid
and b.id=c.wid
and b.id=d.gid ///这里是b和d相关联的
and (c.省份=@省份 or @省份=null)
and (c.城市=@城市 or @城市=null)
and (d.岗位类别=@岗位类别 or @岗位类别=null)
and (d.具体岗位=@具体岗位 or @具体岗位=null)
这么写的话会出来这样的记录
江苏省 南京市 3 16 石油化工类 石油化工类-不限 测试工程师
北京市 不限 4 17 石油工程类 石油工程类-不限 网络工程师
浙江省 杭州市 4 17 石油工程类 石油工程类-不限 网络工程师
北京市 不限 5 17 计算机业(IT)类 计算机业(IT)类 网络工程师
浙江省 杭州市 5 17 计算机业(IT)类 计算机业(IT)类 网络工程师
上海市 不限 6 18 计算机业(IT)类 数据库开发 地址工程师
福建省 福州市 6 18 计算机业(IT)类 数据库开发 地址工程师
上海市 不限 7 18 石油地质类 石油地质类-不限 地址工程师
福建省 福州市 7 18 石油地质类 石油地质类-不限 地址工程师
上海市 不限 8 18 石油储运类 石油储运类-不限 地址工程师
福建省 福州市 8 18 石油储运类 石油储运类-不限 地址工程师象”地址工程师“为什么会出来6个呢,是因为对于地址工程师这条记录来说,有2个工作地区,”上海市-不限"和“福建省-福州市“,而所属的工作岗位有3个,所以出来的就是6个这样的记录,这6个是分别不相同,所以distinct是不行的啊