最佳答案
架构:
-- drop table if exists inventory;
create table inventory
( itemId varchar(20) primary key, -- you choose the sizings
theDate date not null, -- not this is just a date, not a datetime. It follows your picture info
description varchar(200) not null, -- you choose the sizings
stockIn int not null,
stockOut int not null,
onHand int not null,
updtDT datetime not null
)ENGINE=InnoDB;
加载测试数据:
insert inventory(itemId,theDate,description,stockIn,stockOut,onHand,updtDt) values
('6222-B','2014-09-27','Device 5',0,200,600,'2016-04-10 12:00'),
('9000-M','2014-09-27','Widget 1001',0,400,1800,'2016-04-10 12:00'),
('9000-XX','2014-09-28','Gadget 12',0,200,1650,'2016-04-10 12:00');
触摸更新数据的行:
update inventory
set onHand=1900,updtDt=now()
where itemId='9000-XX';
显示今天更新的数据:
select * from inventory where date(updtDt)=current_date();
+---------+------------+-------------+---------+----------+--------+---------------------+
| itemId | theDate | description | stockIn | stockOut | onHand | updtDT |
+---------+------------+-------------+---------+----------+--------+---------------------+
| 9000-XX | 2014-09-28 | Gadget 12 | 0 | 200 | 1900 | 2016-05-29 00:24:51 |
+---------+------------+-------------+---------+----------+--------+---------------------+
1 row in set (0.00 sec)
当然,我的 table 上可能有一个额外的日期。也许您只需要一个日期时间,就是这样(不是日期和日期时间)。但是,当对日期时间列使用 date()
函数时,它只会生成日期输出。因此请进行相应的实验。
关于mysql - 此库存的数据值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37505797/