Skip to content

Completed the Recruting Educators Biz Scenario#28

Open
SOsdoba wants to merge 2 commits into
CPU-Code-School:mainfrom
SOsdoba:main
Open

Completed the Recruting Educators Biz Scenario#28
SOsdoba wants to merge 2 commits into
CPU-Code-School:mainfrom
SOsdoba:main

Conversation

@SOsdoba
Copy link
Copy Markdown

@SOsdoba SOsdoba commented Mar 23, 2023

I completed the Recruiting Educators Biz-Scenario.

Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! See comments, fix and resubmit.

Comment thread RecruitingEducatorsDB/2 table.sql Outdated
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 <> ''),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the constraint

Comment thread RecruitingEducatorsDB/2 table.sql Outdated
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing varchar() use char(1) and add constraint to allow only M or F.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread RecruitingEducatorsDB/2 table.sql Outdated
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,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure it's not before we opened. And not after today's date.

Copy link
Copy Markdown
Author

@SOsdoba SOsdoba Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constraint added

Comment thread RecruitingEducatorsDB/2 table.sql Outdated
SchoolPlaced varchar(30)
constraint c_School_Placed_cannot_be_blank check(SchoolPlaced <> ''),
DateFoundJob date
constraint c_Date_Found_Job_cannot_be_blank check(DateFoundJob <> ''),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A blank date returns a valid date. It returns 01/01/1900.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constraint removed

Comment thread RecruitingEducatorsDB/2 table.sql Outdated
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),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constraint added

Comment thread RecruitingEducatorsDB/2 table.sql Outdated

alter table educators drop column if exists DaysTillJobFound
go
alter table educators add DaysTillJobFound as (datediff(day, DateContacted, DateFoundJob)) persisted
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add the computed column in the table. Just add DaysTillJobFound as (datediff(day, DateContacted, DateFoundJob)) persisted to the bottom of your table.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected

Comment thread RecruitingEducatorsDB/4 reports.sql Outdated
-- 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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use week instead of day.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread RecruitingEducatorsDB/4 reports.sql Outdated
group by e.CollegeAttended

--2. Who were we more successful in placing, males or females?
select top 1 e.Gender
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it clearer what the results are, include the total. And you don't really need top 1.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


--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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change it to count(*), e.media because your results returns .000 for some which doesn't make sense.

Comment thread RecruitingEducatorsDB/4 reports.sql Outdated
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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Age at contact date not current date. And you can use year.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@SOsdoba
Copy link
Copy Markdown
Author

SOsdoba commented Mar 29, 2023

I've made the corrections. Please let me know if there is anything else that needs fixing.

Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! All done. Just see one comment, no need to resubmit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant