如题我想问下表这个怎么设计?DROP TABLE IF EXISTS book_action_tb
CREATE TABLE book_action_tb(
`id` int(11) NOT NULL auto_increment, 
`bookname` varchar(225)  NOT NULL, 
`action_man` varchar(30) NOT NULL,//借出或者归还用户
`action_date` datetime NOT NULL, //借出或者归还日期
`action_status` char(1) NOT NULL, //状态 0借出 1归还
PRIMARY KEY  (`id`)
)ENGINE=InnoDB DEFAULT CHARSET=gbk;我只写了一个表,但是这样不是太好,
如果我要查询超过一个月没有归还的图书就不好写语句

解决方案 »

  1.   

    可以啊
    用一个子查询获得已经借出去的书,然后用现在日期减去借出日期,大于一个月的就是了select * from book_action_tb  t1 where t1.id in (select id from book_action_tb t2 where t2.action_status='t') and current_date-actiondate>1 month(or 31dat)
    mysql获得系统时间的函数不知道,查查就可以了 
      

  2.   

    Base on this table.select * from book_action_tb where action_status = 0 and action_date >= date_sub(now(),interval 1 month);