implemented Bike-shop bussiness scenario#55
Conversation
| BikeCompany varchar(100) not null constraint ck_Bike_Company_cannot_be_blank check(BikeCompany <> ''), | ||
| BikeSize varchar(6) not null constraint ck_Bike_Size_cannot_be_blank check(BikeSize <> ''), | ||
| BikeColor varchar(15) not null constraint ck_Bike_Color_cannot_be_blank check(BikeColor <> ''), | ||
| DatePurchased date not null constraint ck_Date_Purchased_must_be_after_1st_of_march_2022 check(DatePurchased > '2022-03-01'), |
There was a problem hiding this comment.
Make sure that DatePurchased is not in the future. This condition can be combined with the constraint below.
| BikeSize varchar(6) not null constraint ck_Bike_Size_cannot_be_blank check(BikeSize <> ''), | ||
| BikeColor varchar(15) not null constraint ck_Bike_Color_cannot_be_blank check(BikeColor <> ''), | ||
| DatePurchased date not null constraint ck_Date_Purchased_must_be_after_1st_of_march_2022 check(DatePurchased > '2022-03-01'), | ||
| PurchasePrice decimal(6,2) not null, |
There was a problem hiding this comment.
Make sure that PurchasePrice is greater than 0.
| BikeColor varchar(15) not null constraint ck_Bike_Color_cannot_be_blank check(BikeColor <> ''), | ||
| DatePurchased date not null constraint ck_Date_Purchased_must_be_after_1st_of_march_2022 check(DatePurchased > '2022-03-01'), | ||
| PurchasePrice decimal(6,2) not null, | ||
| New varchar (12) constraint ck_New_column_must_be_either_New_or_Used check(New in('new','Used')), |
There was a problem hiding this comment.
A better practice would be to use a bit datatype for the column 'New'.
| DatePurchased date not null constraint ck_Date_Purchased_must_be_after_1st_of_march_2022 check(DatePurchased > '2022-03-01'), | ||
| PurchasePrice decimal(6,2) not null, | ||
| New varchar (12) constraint ck_New_column_must_be_either_New_or_Used check(New in('new','Used')), | ||
| ConditionReceived varchar (11), |
There was a problem hiding this comment.
An improvement would be to record the condition as an INT column with a computed column for descriptions.
| PurchasePrice decimal(6,2) not null, | ||
| New varchar (12) constraint ck_New_column_must_be_either_New_or_Used check(New in('new','Used')), | ||
| ConditionReceived varchar (11), | ||
| dateSold date, |
There was a problem hiding this comment.
- Change date Sold to proper case (DateSold instead of dateSold).
- Make sure that DateSold is not in the future.
| New varchar (12) constraint ck_New_column_must_be_either_New_or_Used check(New in('new','Used')), | ||
| ConditionReceived varchar (11), | ||
| dateSold date, | ||
| season varchar(10) not null constraint ck_season_cannot_be_blank check(season <> ''), |
There was a problem hiding this comment.
Season should be a computed column based on the date sold.
| ConditionReceived varchar (11), | ||
| dateSold date, | ||
| season varchar(10) not null constraint ck_season_cannot_be_blank check(season <> ''), | ||
| SalePrice decimal(6,2) constraint ck_Sale_price_cannot_be_more_then_3000 check(SalePrice <3001), |
There was a problem hiding this comment.
Make sure that SalePrice is greater than 0. This condition can be combined with the constraint below.
| CONSTRAINT ck_Condition_Received_for_a_used_bike_must_be_either_In_Perfect_or_Minor_fixup_or_Major_fixup_or_Restoration | ||
| CHECK (new <> 'used' or ConditionReceived in('Perfect', 'Minor Fixup', 'Major Fixup', 'Restoration')), | ||
| constraint ck_Date_sold_must_be_after_date_purchased check(dateSold > DatePurchased) | ||
| ) |
There was a problem hiding this comment.
Ensure that for a new bike, the ConditionReceived column is null, and for a used bike the column has a value.
There was a problem hiding this comment.
Working with nulls is causing an error when it comes to combine varchar velues in the Desc column, I did it a different way, please let me know if it's ok.
| go | ||
|
|
||
| --1) I would like to know how many local customers I have as oppose to out-of-town customers. | ||
| select |
There was a problem hiding this comment.
Make sure that the result excludes null addresses.
There was a problem hiding this comment.
Fixed (just to clarify, the spec didn't mention that non sold bikes are included in the data)
| count(case when b.CustomerAddress not like '%Spring Valley%' then 1 end) as OutOfTownCustomers | ||
| from bike b | ||
|
|
||
| --2) The amount of bikes sold per season to know what is my busiest season. |
There was a problem hiding this comment.
You might want to add a filter to include only bikes that were sold.
There was a problem hiding this comment.
Fixed (again the spec sounds like we talk about sold bikes only)
| order by AmountSold desc | ||
|
|
||
| --3) I need a report with the average, minimum and maximum amount of time a bike was in my store before I sold it. Also show in this report my total profit so far. | ||
| select |
There was a problem hiding this comment.
Make sure to include only bikes that were sold.
| from bike b | ||
|
|
||
| --4) I need a report with the profit for each sale and show the Customers name, BikeCompany, PurchasePrice, SoldPrice, New/Used. | ||
| select b.CustomerName, b.BikeCompany, b.PurchasePrice, b.SalePrice, b.New, b.SalePrice - b.PurchasePrice as Profit |
There was a problem hiding this comment.
Same, make sure to include only bikes that were sold.
|
Please take a look at my latest commit and let me know if everything is resolved. |
Pull request for Bike-shop Biz-scenario