Costume#45
Conversation
astrohlicpu
left a comment
There was a problem hiding this comment.
Nice job! Please see my comments
| CustomerLastName varchar(25) not null, | ||
| constraint c_Costume_customer_last_name_cannot_be_blank check(CustomerLastName > ''), | ||
| CostumesBought varchar(100) not null, | ||
| constraint c_Costume_costumes_bought_must_be_one_of_the_costume_choices |
There was a problem hiding this comment.
So far they are only selling those costumes, but since this may change we wouldn't constrain it.
| constraint c_Costume_costumes_bought_must_be_one_of_the_costume_choices | ||
| check(CostumesBought in ('American Girl Doll', 'Artist', 'Bumble Bee', 'Colonial Boy', 'Colonial Girl', 'Elephant', 'Fire Man', 'Police Man', 'Princess', 'Zebra')), | ||
| CostumeSize varchar(2) not null, | ||
| constraint c_Costume_costume_size_cannot_be_blank check(CostumeSize > ''), |
There was a problem hiding this comment.
Here the spec says that there are only 5 options. You can therefor safely make a constraint to only these 5 options.
| constraint c_Costume_costume_size_cannot_be_blank check(CostumeSize > ''), | ||
| CostumeAmount int not null, | ||
| constraint c_Costume_costume_amount_must_be_greater_than_zero check (CostumeAmount > 0), | ||
| CostumeCostPrice int not null, |
There was a problem hiding this comment.
Since the price is dependent on the size, you can compute it of the size.
| TotalPrice as CostumeSoldPrice * CostumeAmount persisted, | ||
| constraint c_Costume_sold_price_must_be_more_than_or_equal_to_cost_price check(CostumeSoldPrice >= CostumeCostPrice), | ||
| constraint c_Costume_date_sold_must_be_on_or_after_date_bought check(DateSold >= DateBought), | ||
| constraint c_Costume_total_price_must_be_greater_than_or_equal_to_sold_price check(TotalPrice >= CostumeSoldPrice) |
There was a problem hiding this comment.
Since the total price is a computed column, there is no need for this constraint.
| go | ||
|
|
||
| --1. I need to know which costume is the most popular. | ||
| select top 1 AmountPerCostume = count (*), c.CostumesBought |
There was a problem hiding this comment.
You can have a costume which is only in one row in the table, but was the AmountBought can be 12, which would make it the most popular column
| group by c.CostumesBought | ||
| order by AmountPerCostume desc | ||
|
|
||
| --2. I need to know which size is the most polpular. |
There was a problem hiding this comment.
Same issue as previous report
No description provided.