开发者

Database structure / defined and undefined field values

I am using MySQL and have an articles table which has 2 columns: currency and price, but an article can also have a negotiated price, so I can't determine currency and price values.

What should I开发者_开发技巧 do to be able to have defined and negotiated prices?


If the negotiated price is specific to a user/business... , then this is probably a one to many relationship, you will need a tuple table to hold the price and link the article to the other object.

e.g: (I'll assume the price is negotiated with a user)

CREATE TABLE user_article_price (          
    articleid INT,          
    userid    INT,        
    price     DECIMAL(13,2)
)

You then simply need to LEFT JOIN to this table and use NVL(user_article_price.price, article.price) to get the overridden value.

Note: It is probably a good idea to make a compound primary key using the 2 id columns to stop duplicate values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜