I need to model an idea which can be broken down and thought of as follows:
- BookDetails
- BookPrices
The problem here is that you can have many prices for books and these prices are likely to change. Here's an example
BookDetails: ----------------- ID Name 1 Harry Potter…
This is easy enough.
Where it is more interesting is that for this one book I might have ten different prices on that day, e.g.:
BookPrices: ------------------------------------ Book_Details_Id Kind Price 1 SpecialOffer 10 1 BulkPurchase 20 1 Normal 30
I need to provide a list of books and all their prices in columns - something like:
BookName SpecialOffer BulkPurchase Normal Harry Potter… 10 20 30
My question is: Should the book price table actually have all the different price types as columns? To me this is ugly and a better idea is to have each price as a row
If I use that approach I cannot think of a SQL query to generate me the result set. I have been thinking about this all morning.
EDIT: I have no leeway on calculating prices - they have to be stored down.
EDIT: This is basically the 1-n appraoch I can think of (Thanks to comment below) - Its what I actually had in mind
SELECT book.bookid, bp1.price, bp2.price FROM book JOIN bookprice bp1 JOIN bookprice bp2 ON bp1.bookid = book.bookid AND bp1.pricetype=1 AND bp2.bookid = book.bookid AND bp2.pricetype=2...
The problem is for ten prices you will be joining ten times which stinks!