Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL日期\添加,日期子查询_Mysql_Date_Dateadd - Fatal编程技术网

MySQL日期\添加,日期子查询

MySQL日期\添加,日期子查询,mysql,date,dateadd,Mysql,Date,Dateadd,我正试图从tbl_提供的产品中检索有提供的产品(tbl_产品) offerid,productid,discountrate,dateadded,days tbl_提供的栏目 offerid,productid,discountrate,dateadded,days 其中offerid和productid是自动递增的ID,Discentrate是int,dateadded timestamp和days int 它的基本意思是,报价在添加后的10天内有效。天数可以有不同的值 以下是我正在尝试的

我正试图从tbl_提供的产品中检索有提供的产品(tbl_产品)

offerid,productid,discountrate,dateadded,days
tbl_提供的栏目

offerid,productid,discountrate,dateadded,days
其中offerid和productid是自动递增的ID,Discentrate是int,dateadded timestamp和days int

它的基本意思是,报价在添加后的10天内有效。天数可以有不同的值

以下是我正在尝试的查询:

select a.* from tbl_product a, tbl_offers b 
where a.productid=b.productid and 
date_add(dateadded, interval (select days from tbl_offers) day)>NOW();
抛出一个错误,表示子查询返回多行


我不知道如何将我的查询定位为从子查询中获得天数

您不需要子查询,使用join可以完成

select 
a.*
from 
tbl_product a
join tbl_offers b  on a.productid=b.productid
where
date_add(b.dateadded, interval b.days day ) > now() ;