Completed the Recruting Educators Biz Scenario#28
Conversation
ghost
left a comment
There was a problem hiding this comment.
Excellent! See comments, fix and resubmit.
| LastName varchar(20) not null | ||
| constraint c_Last_Name_cannot_be_blank check(LastName <> ''), | ||
| DOB date not null | ||
| constraint c_DOB_cannot_be_blank check(DOB <> ''), |
There was a problem hiding this comment.
A blank date returns a valid date. It returns 01/01/1900. Either use constraint that it must be after specific date, or don't use constraint at all. You don't need a constraint for < getdate() because you have a multi column constraint that it must be before DateContacted.
| constraint c_Last_Name_cannot_be_blank check(LastName <> ''), | ||
| DOB date not null | ||
| constraint c_DOB_cannot_be_blank check(DOB <> ''), | ||
| Gender varchar(15) not null |
There was a problem hiding this comment.
Instead of doing varchar() use char(1) and add constraint to allow only M or F.
| constraint c_Title_of_Degree_cannot_be_blank check(TitleOfDegree <> ''), | ||
| Media varchar(20) not null | ||
| constraint c_Media_is_either_magazine_or_newspaper_or_social_media_site_or_word_of_mouth check(Media in ('Magazine', 'Newspaper', 'Social media site', 'Word of mouth')), | ||
| DateContacted date not null, |
There was a problem hiding this comment.
Make sure it's not before we opened. And not after today's date.
| SchoolPlaced varchar(30) | ||
| constraint c_School_Placed_cannot_be_blank check(SchoolPlaced <> ''), | ||
| DateFoundJob date | ||
| constraint c_Date_Found_Job_cannot_be_blank check(DateFoundJob <> ''), |
There was a problem hiding this comment.
A blank date returns a valid date. It returns 01/01/1900.
| constraint c_Date_Found_Job_cannot_be_blank check(DateFoundJob <> ''), | ||
| constraint c_DateFoundJob_and_SchoolPlaced_are_both_null_or_both_have_value check((SchoolPlaced is null and DateFoundJob is null) or (SchoolPlaced is not null and DateFoundJob is not null)), | ||
| constraint c_DateContacted_is_after_DOB_and check(DOB <= DateContacted), | ||
| constraint c_Date_Contacted_not_before_Feb_17_2017_and_not_after_date_found_job check(DateContacted between '02/17/2017' and datefoundjob), |
There was a problem hiding this comment.
Because you do allow null in DateFoundJob, this constraint won't restrict it to not allow future dates. And because of this null issue, you need a constraint that DateFoundJob is between DateContacted and today.
|
|
||
| alter table educators drop column if exists DaysTillJobFound | ||
| go | ||
| alter table educators add DaysTillJobFound as (datediff(day, DateContacted, DateFoundJob)) persisted |
There was a problem hiding this comment.
You can add the computed column in the table. Just add DaysTillJobFound as (datediff(day, DateContacted, DateFoundJob)) persisted to the bottom of your table.
| -- This will help my company know which college's graduates we should try to attract to our company. | ||
| select e.CollegeAttended, AmntOfStudents = count(*) | ||
| from Educators e | ||
| where datediff(day, DateContacted, DateFoundJob) < 14 |
| group by e.CollegeAttended | ||
|
|
||
| --2. Who were we more successful in placing, males or females? | ||
| select top 1 e.Gender |
There was a problem hiding this comment.
To make it clearer what the results are, include the total. And you don't really need top 1.
|
|
||
| --3. On average, how many people contact us every day and how many people fnd out about us per form of media. | ||
| -- This will help us decide which forms of media communication we should invest in. | ||
| select AvgPplContactedUs = convert(decimal(10,8), count(e.EducatorID)) / datediff(day, '02-17-2017', getdate()), e.Media |
There was a problem hiding this comment.
For this and next 2 questions, use count(*), the question needs to be modified because as of session 20 you can't do count() with avg(), you'll need a CTE which you'll learn in session 24.
There was a problem hiding this comment.
Ok, so do I need to correct them? Because from what I see the way I did it produces the result. Unless you're saying to switch to --count(*), e.media?
There was a problem hiding this comment.
Change it to count(*), e.media because your results returns .000 for some which doesn't make sense.
| group by e.TitleOfDegree | ||
|
|
||
| --6. I need a list of the educators who reach out to us in the format of first name, last name, age, - degree. | ||
| select Educators = concat(firstname, ', ', lastname, ', ', (datediff(day, DOB, getdate()))/365, ', - ', titleofdegree) |
There was a problem hiding this comment.
Age at contact date not current date. And you can use year.
There was a problem hiding this comment.
I switched it to contact date. I left it as day/365 and not year because year just subtracts the 2 years, and doesn't always give an accurate age if it isn't a complete year.
|
I've made the corrections. Please let me know if there is anything else that needs fixing. |
ghost
left a comment
There was a problem hiding this comment.
Great! All done. Just see one comment, no need to resubmit.
I completed the Recruiting Educators Biz-Scenario.