我希望有人可以提供帮助。我创建了这个存储过程来从不同的表中提取一些信息,当我调整它时,我得到了很多重复,我想知道是否有一种方法对它进行排序?
use ICA
if exists(
select *
from INFORMATION_SCHEMA.ROUTINES
where SPECIFIC_SCHEMA = N'ICASchema'
and SPECIFIC_NAME = N'candidateOffer'
)
drop procedure ICASchema.candidateOffer
go
create procedure ICASchema.candidateOffer @candidateID INT
as
begin
select c.CandidateID,c.CandidateName, ca.CourseID, co.CourseName, o.OfferID, ot.OfferTypePoints
from [ICASchema].[tblCandidate] c
join [ICASchema].[tblCandidateOffer] o on c.CandidateID = o.CandidateID
join [ICASchema].[tblOffer] ot on o.offerID = ot.OfferType
join [ICASchema].[tblCandidateApplication] ca on ca.CourseID = ca.CourseID
join [ICASchema].[tblCourse] co on co.CourseName = co.CourseName
where c.CandidateID = @candidateID
--ORDER BY co.CourseName
GROUP BY co.CourseName, c.CandidateID,c.CandidateName, ca.CourseID, o.OfferID, ot.OfferTypePoints
end
go
由于
格雷厄姆
答案 0 :(得分:0)
试试这个:
select * from (select distinct c.CandidateID,c.CandidateName, ca.CourseID, co.CourseName, o.OfferID, ot.OfferTypePoints
from [ICASchema].[tblCandidate] c
join [ICASchema].[tblCandidateOffer] o on c.CandidateID = o.CandidateID
join [ICASchema].[tblOffer] ot on o.offerID = ot.OfferType
join [ICASchema].[tblCandidateApplication] ca on ca.CourseID = ca.CourseID
join [ICASchema].[tblCourse] co on co.CourseName = co.CourseName
where c.CandidateID = @candidateID
GROUP BY co.CourseName, c.CandidateID,c.CandidateName, ca.CourseID, o.OfferID, ot.OfferTypePoints) tablealias order by CourseName
答案 1 :(得分:0)
以下示例用于创建简单的Proc_GetAllUsers存储过程。这将解决您的重复问题。
如果出现{DIG PROCEDURE Proc_GetAllUsers
GO
CREATE PROCEDURE Proc_GetAllUsers() 开始
- 你的SQL查询 选择* FROM用户;
结束
开始
答案 2 :(得分:0)
这是可行的解决方案。
[code] SELECT c.CandidateID,c.CandidateName,ICASchema.tblOffer.OfferTypePoints,ICASchema.tblCourse.CourseName 来自ICASchema.tblCandidate AS c INNER JOIN ICASchema.tblCandidateOffer ON c.CandidateID = ICASchema.tblCandidateOffer.CandidateID INNER JOIN ICASchema.tblOffer ON ICASchema.tblCandidateOffer.CandidateOfferID = ICASchema.tblOffer.OfferID INNER JOIN ICASchema.tblCourse on ICASchema.tblOffer.OfferID = ICASchema.tblCourse.OfferTypeID WHERE(c.CandidateID ='3') [/代码]