Implemented the Cleaning Company Scenario #35
Conversation
ghost
left a comment
There was a problem hiding this comment.
Excellent work! See comments, fix and resubmit.
| drop TABLE if EXISTS dbo.CleaningCompany | ||
| go | ||
| CREATE table dbo.CleaningCompany( | ||
| CustomerID int not null IDENTITY primary key, |
There was a problem hiding this comment.
The PK should be the name of the table + Id. Either change the table name or the PK column name.
| 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 <> ''), |
There was a problem hiding this comment.
Address should be unique. As you can have multiple times the same customer but in different addresses.
| 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 ), |
There was a problem hiding this comment.
This should have some sort of decimal place as this should be the avg hours and it can be 1.5 hours.
There was a problem hiding this comment.
switched the datatype to decimal
| 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 <> ''), |
| 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) | ||
| ) |
There was a problem hiding this comment.
We need a computed column that returns total per month.
| */ | ||
| SELECT DeepCleanCustomers= CONCAT(c.LastName, ' ', c.FirstName, ' (',c.PhoneNumber, ') - ', (c.PricePerHour*c.TimeinHours) ) | ||
| FROM CleaningCompany C | ||
| where c.PricePerHour >=35 |
There was a problem hiding this comment.
No need for where clause as the data in table are for regular cleans only.
There was a problem hiding this comment.
took out the where clause and add to the select to multiply by 1.5 to show the price would charge for a deepclean
| 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) |
There was a problem hiding this comment.
This should be one select with 2 columns one for regular and one for deep.
There was a problem hiding this comment.
but there are no deep cleans in this table?
There was a problem hiding this comment.
Yes. But show how much it will be the avg price for deep cleans calculating the difference between deep and regular cleans.
ghost
left a comment
There was a problem hiding this comment.
Excellent improvements. See comments, fix and resubmit.
| 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) |
There was a problem hiding this comment.
Yes. But show how much it will be the avg price for deep cleans calculating the difference between deep and regular cleans.
| 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 <> ''), |
There was a problem hiding this comment.
Remove the commas between column and constraints.
|
|
||
| Alter Table Customer drop column if EXISTS TotalPerMonth | ||
| go | ||
| ALTER table customer add TotalPerMonth as |
There was a problem hiding this comment.
Computed column can be part of table. Just do same as normal column but instead of doing ColumnName datatype do ColumnName as.
| 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) ) |
There was a problem hiding this comment.
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.
I have created a database and implemented the Cleaning Company Scenario