比如,某个物品,在某个时间段的价格是一个价,在另外个时间段的时候又是另一种价。例如: 物品A, 在 2010年8月12到2010年8月20,是500元;
在 2010年8月20到2010年8月30, 是700元;
在 2010年9月1日到2010年9月12, 是200元;
... ...
... ...1)如何建表存储 这样的 物品和其对应的时间段及价格,
2)如何查询其中某一天的价格。例如物品A,在2010年8月17日价格是多少
3)如何查询某个时间段价格。例如物品A,在2010年8月17到2010年8月23的价格,就有两种。
在 2010年8月20到2010年8月30, 是700元;
在 2010年9月1日到2010年9月12, 是200元;
... ...
... ...1)如何建表存储 这样的 物品和其对应的时间段及价格,
2)如何查询其中某一天的价格。例如物品A,在2010年8月17日价格是多少
3)如何查询某个时间段价格。例如物品A,在2010年8月17到2010年8月23的价格,就有两种。
==》
create table tb
(
name varchar(10),
begTime datetime,
endTime datetime,
price int
)2)如何查询其中某一天的价格。例如物品A,在2010年8月17日价格是多少
==>
select *
from tb
where name='A' and '2010-08-17' between begTime and endTime
3)如何查询某个时间段价格。例如物品A,在2010年8月17到2010年8月23的价格,就有两种。
===>
select *
from tb
where name='A' and ((begTime<='2010-08-17' and entTime>='2010-08-17') or
(begTime>='2010-08-17' and endTime>='2010-08-23'))
OR
物品ID 开始时间 结束时间 价格
(
goodsID int(11),
TTime datetime,
price int,
KEY `idx_goodsID` (`goodsID `)
)我觉得可以只要三个字段,每天的价格都保存一次。另外这个表存物品ID,不存名称,需要名称到物品表去关联查询。两个表用goodsID主键关联。
create table tb (goodsid int ,goodsname varchar(100), pirce int ,updatetime datetime)updatetime存价格 更改的时间段的开始时间
下一次更改的时候再存开始时间
select * from tb where updatetime <= '2010-08-17' order by updatetime desc limit 1;
8月17日时的价格
2)如何查询其中某一天的价格。例如物品A,在2010年8月17日价格是多少select price from tb,goods using(goodsid) where goods.goodsname='A' and tb.ttime='2010-08-17';3)如何查询某个时间段价格。例如物品A,在2010年8月17到2010年8月23的价格,就有两种。
select distinct(price) from tb,goods using(goodsid) where goods.goodsname='A' and tb.ttime between '2010-08-17' and '2010-08-123';