|
Hi to all u SQL Gurus out there!
could someone help me with my query
please?
I have the following tables
Skill Attempt:
//holds all attempts at "skill" even failed and disqualified (for
licences)
SkillAttemptID
//eg licence attempts etc
PersonID
AttemptDate
ValidTo
ProviderDI
SkillID
Result
Ref
Comments
Skill:
//holds names of skills
and time valid
SkillID
Name
TimeValid
CompanyID
SkillNeeded:
//holds what skills are required for what job
SkillNeededID
EmploymentID
TimePeriodID
SkillID
Employment:
//job names
EmploymentID
Name
TimePeriod:
//time periods in weeks for select box
TimePeriodID
Weeks
PersonEmployment:
//who does what jobs
PersonEmploymentID
CommenceDate
PersonID
PErson:
personid
name
etc
In the SkillNeeded table, some skills are required
within a certain period of beginning a job. these hold a foreign key
linking to timeperiod
if the skill is a prerequisite, the value will be
0
if there is no time limit, the
skillneeded.timeperiodid will be null - hence the left join
i have the following sql to show what skills a
person requires that they do not yet have:
select distinct pe.commencedate, sn.skillid,
s.name, sn.timeperiodid, tp.weeks
from personemployment pe join skillneeded sn on sn.employmentid = pe.employmentid left join timeperiod tp on tp.timeperiodid = sn.timeperiodid join skill s on s.skillid = sn.skillid where pe.personid = 4 and sn.skillid not in (select skillid from skillattempt where (personid = 4 and skillid = sn.skillid and result = 'P' and (validto is null or validto > '02/11/2003'))) Some skills are required in more than one
job. If this person has both those jobs and doesnt have that skill, then
the query returns the skill for as many times as it is needed.
What i really want, is for the skill itsself to be
only returned once, with the earliest timeperiod. Is this possible in SQL
or do i need to frig with code? (distinct isnt working with all my
joins)
|
- Re: [DUG]: sql help please Tracey Maule
- Re: [DUG]: sql help please Nello Sestini
- Re: [DUG]: sql help please Tracey Maule
- Re: [DUG]: sql help please Ian Fear
- Re: [DUG]: sql help please Tracey Maule
- Re: [DUG]: sql help please Tracey Maule
- Re: [DUG]: sql help please Neven MacEwan
