Skip to content

Implemented the Cleaning Company Scenario #35

Open
RiFinkelstein wants to merge 16 commits into
CPU-Code-School:mainfrom
RiFinkelstein:main
Open

Implemented the Cleaning Company Scenario #35
RiFinkelstein wants to merge 16 commits into
CPU-Code-School:mainfrom
RiFinkelstein:main

Conversation

@RiFinkelstein
Copy link
Copy Markdown

I have created a database and implemented the Cleaning Company 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 work! See comments, fix and resubmit.

Comment thread 1 table.sql
drop TABLE if EXISTS dbo.CleaningCompany
go
CREATE table dbo.CleaningCompany(
CustomerID int not null IDENTITY primary key,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The PK should be the name of the table + Id. Either change the table name or the PK column name.

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 the tablename

Comment thread 1 table.sql Outdated
FirstName varchar(50) not null constraint ck_Customer_First_name_is_not_blank CHECK (FirstName <> ''),
LastName varchar(50) not null constraint ck_Customer_Last_name_is_not_blank CHECK (LastName <> ''),
PhoneNumber varchar(15) not null constraint ck_Customer_Phone_Number_is_not_blank CHECK (PhoneNumber <> ''),
CustomerAddress VARCHAR(50) not null constraint ck_Customer_Address_is_not_blank CHECK (CustomerAddress <> ''),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Address should be unique. As you can have multiple times the same customer but in different addresses.

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.

added unique contraint

Comment thread 1 table.sql Outdated
CustomerAddress VARCHAR(50) not null constraint ck_Customer_Address_is_not_blank CHECK (CustomerAddress <> ''),
Frequency VARCHAR(9) not null constraint ck_Customer_frequency_must_be_either_weekly_or_biweekly check (frequency in ('Weekly', 'BiWeekly')),
PricePerHour int not null CONSTRAINT ck_Customer_PricePerHour_is_between_0_and_53 check (PricePerHour between 0 and 53),
TimeinHours int not null CONSTRAINT ck_Customer_TimeinHours_is_between_greater_than_0 check (TimeinHours >0 ),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should have some sort of decimal place as this should be the avg hours and it can be 1.5 hours.

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.

switched the datatype to decimal

Comment thread 1 table.sql Outdated
Frequency VARCHAR(9) not null constraint ck_Customer_frequency_must_be_either_weekly_or_biweekly check (frequency in ('Weekly', 'BiWeekly')),
PricePerHour int not null CONSTRAINT ck_Customer_PricePerHour_is_between_0_and_53 check (PricePerHour between 0 and 53),
TimeinHours int not null CONSTRAINT ck_Customer_TimeinHours_is_between_greater_than_0 check (TimeinHours >0 ),
StartDate date not null CONSTRAINT ck_Customer_Satrt_date_is_not_blank CHECK (startdate <> ''),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should be after company opened.

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.

changed the constraint

Comment thread 1 table.sql Outdated
EndDate date null,
constraint ck_start_date_is_before_end_date check (StartDate < EndDate),
constraint ck_price_per_hour_times_hours_is_less_than_424 check (PricePerHour * TimeinHours < 424)
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We need a computed column that returns total per month.

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.

added a computed column

Comment thread 1 table.sql Outdated
Comment thread 3 reports.sql Outdated
*/
SELECT DeepCleanCustomers= CONCAT(c.LastName, ' ', c.FirstName, ' (',c.PhoneNumber, ') - ', (c.PricePerHour*c.TimeinHours) )
FROM CleaningCompany C
where c.PricePerHour >=35
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No need for where clause as the data in table are for regular cleans only.

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.

took out the where clause and add to the select to multiply by 1.5 to show the price would charge for a deepclean

Comment thread 3 reports.sql Outdated
ORDER BY NumberOfMonths desc

--3) What is the average price I ask per hour for regular cleans and what is the average price per hour for deep cleans?
SELECT AvergaePricePerHourRegularClean = avg(c.PricePerHour)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should be one select with 2 columns one for regular and one for deep.

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.

but there are no deep cleans in this table?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes. But show how much it will be the avg price for deep cleans calculating the difference between deep and regular cleans.

Comment thread 3 reports.sql Outdated
Comment thread 3 reports.sql
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 improvements. See comments, fix and resubmit.

Comment thread 3 reports.sql Outdated
ORDER BY NumberOfMonths desc

--3) What is the average price I ask per hour for regular cleans and what is the average price per hour for deep cleans?
SELECT AvergaePricePerHourRegularClean = avg(c.PricePerHour)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes. But show how much it will be the avg price for deep cleans calculating the difference between deep and regular cleans.

Comment thread 1 table.sql Outdated
FirstName varchar(50) not null constraint ck_Customer_First_name_is_not_blank CHECK (FirstName <> ''),
LastName varchar(50) not null constraint ck_Customer_Last_name_is_not_blank CHECK (LastName <> ''),
PhoneNumber varchar(15) not null constraint ck_Customer_Phone_Number_is_not_blank CHECK (PhoneNumber <> ''),
CustomerAddress VARCHAR(50) not null, constraint u_Customer_Address UNIQUE (CustomerAddress), constraint ck_Customer_Address_is_not_blank CHECK (CustomerAddress <> ''),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove the commas between column and constraints.

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.

done

Comment thread 1 table.sql Outdated

Alter Table Customer drop column if EXISTS TotalPerMonth
go
ALTER table customer add TotalPerMonth as
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Computed column can be part of table. Just do same as normal column but instead of doing ColumnName datatype do ColumnName as.

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.

done

Comment thread 3 reports.sql Outdated
For this I need to see the customers phone number, last name and the amount of money they will have to pay.
Please do it in this format: last name, first name (phone number) - price of service.
*/
SELECT DeepCleanCustomers= CONCAT(c.LastName, ' ', c.FirstName, ' (',c.PhoneNumber, ') - ', (c.PricePerHour*c.TimeinHours*1.5) )
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 didn't add the comma. And you need to add to the calculation for deep cleans that the price is 50% more but the time is also * 2.

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.

done

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! 100% All good.

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