【发布时间】:2016-10-07 18:20:41
【问题描述】:
我正在研究两个相似的 SQL,只是不同之处在于第一个查询股票是在两个日期之间计算的,第二个查询使用当前日期。
PHP:
$sql="select all_dates.value1 as `Date`, sum(coalesce(`Inward(B_Qty)`, '0')) as `Inward`, sum(coalesce(`Outward(B_Qty)`, '0')) as `Outward`
from ( select distinct M_Date as value1 from machine where J_Name = '180MLGMV' and DATE(M_Date) between '2016-06-01' and '2016-06-06'
union select distinct M_Date from machine where Pre_Req = '180MLGMV' and DATE(M_Date) between '2016-06-01' and '2016-06-06' ) as all_dates
left join (select M_Date, sum(A_Prod) AS `Inward(B_Qty)`
from machine where J_Name = '180MLGMV' and DATE(M_Date) between '2016-06-01' and '2016-06-06' group by M_Date)
as g on g.M_Date = all_dates.value1
left join( select M_Date, sum(NoBot) AS `Outward(B_Qty)`
from machine where Pre_req ='180MLGMV' and DATE(M_Date) between '2016-06-01' and '2016-06-06' group by M_Date)
as f on f.M_Date = all_dates.value1 group by all_dates.value1 ;" ;
$sql.="select all_dates.value1 as `Date`, sum(coalesce(`Inward(B_Qty)`, '0')) as `Inward`, sum(coalesce(`Outward(B_Qty)`, '0')) as `Outward`
from ( select distinct M_Date as value1 from machine where J_Name = '180MLGMV' and M_Date='2016-06-07'
union select distinct M_Date from machine where Pre_Req = '180MLGMV' and M_Date='2016-06-07' ) as all_dates
left join (select M_Date, sum(A_Prod) AS `Inward(B_Qty)`
from machine where J_Name = '180MLGMV' and M_Date='2016-06-07' group by M_Date)
as g on g.M_Date = all_dates.value1
left join( select M_Date, sum(NoBot) AS `Outward(B_Qty)`
from machine where Pre_req ='180MLGMV' and M_Date='2016-06-07' group by M_Date)
as f on f.M_Date = all_dates.value1 group by all_dates.value1 ";
$list1=mysqli_multi_query($sql,$con);
while($row_list1=mysql_fetch_array($list1))
{
$b=$b+$row_list1['Inward'];
$c=$c+$row_list1['Outward'];
}
请建议如何检索每个Query的Date,Inward和Outward的数据。我的意思是在mysqli_multi_query下面应该写什么来检索这四个数据。
提前致谢。
【问题讨论】:
-
请转至w3schools.com/php/func_mysqli_multi_query.asp。首先要有明确的想法。
-
@RyanVincent 实际上我已经尝试过那里的查询工作绝对正常。我只是对检索值感到困惑。
-
@NanaPartykar 是的。我正在经历那个只是......谢谢。
-
嘿@RyanVincent,为什么要说对不起人。你给了你的建议。在 SO 中总是受欢迎的。
标签: php mysqli mysqli-multi-query