Hi,
I’m having some difficulties with two queries. I can get some of the information but my problem lies in the some special conditions I just can’t seem to get right in the SQL statement.
The first query is in natural language defined:
I’m going to find all the candidates who has acquired two qualifications but during the same time period, but from different institutes
My Relational schema looks like this:
BOLD = primary key
ITALICS = foreign key
candidate = (candidateid, name, birth, mail)
qualification = (qualificationid, instituteid, candidateid, datestarted, datefinished, degreename, major)
institute = (instituteid, institutename, city)
The SQL I’ve tried to run is not very pretty (at this point) and not working either but it is:
select (candidate.firstname, candidate.lastname)
from candidate, qualification, institute
where (select count(qualification.candidateid) from qualification where qualification.candidateid = 2)
and between qualification.datestarted and qualification.datefinished
and qualification.instituteid <> qualification.instituteid
I gives me an error and I’m pretty, almost certain that it is in the COUNT clause but I can’t seem to crack it to how to count the numbers of candidateid’s and set a condition to two (2) and then I’m pretty sure as well that there is a problem in my checking on the time period. They have to be in the same time period. And by the way, the datestarted and the datefinished is in the DATE format.
My second query I’m having problems with is in natural language formulated like this:
Find the names of the companies who have all made inquiries about the candidates but with an average age below 30 (for the candidates).
My relation schemas look like this:
candidate = (candidateid, name, birth, mail)
qualification = (qualificationid, instituteid, candidateid, datestarted, datefinished, degreename, major)
inquiry = (inquiryid,candidateid, companyid)
The query I’ve tried is this:
select (company.companyname) as company
from company, inquiry, candidates
where company.companyid = inquiry.companyid
and inquiry.candidateid = candidate.candidateid
and (select avg(candidate.birth < (right(curdate(),5<right(birth,5)) from candidate)))
The BIRTH tuble is also described as a DATE field.
I hope you can help me out whit these two queries and if there is any question about 'em, please say so and I'll try to clarify.
Mestika