如何解决mysql Complex QUERY?

时间:2015-09-21 12:20:17

标签: php mysql

参考我之前的问题。

How to further filter GROUP BY record in mysql? 有三个不同的页面,我将使用相同的查询,但具有不同的日期,如下所示: 在week_fallowup.php中,日期范围是

s_date = 21/2015年9月

e_date = 28/2015年9月

在fornight_fallowup.php日期范围是

s_date = 29/2015年9月

e_date = 13 / Oct / 2015

在month_fallowup.php中,日期范围是

s_date = 14/2015年9月

有三个后续页面Week_followup.php,Fornight_followup.php& Month_followup.php,我正在使用以下三个查询:

/////////////   QUERY for week_followup.php  \\\\\\\\\\\\\\\\\\\\\
$sql="SELECT * FROM sales_queries AS sq INNER JOIN ( SELECT MAX(Query_id) AS mId FROM sales_queries WHERE follow_up BETWEEN '".$s_date."' AND '".$e_date."' GROUP BY nic_id ) AS subsq ON subsq.mId = sq.Query_id";

///////////// QUERY for fornight_followup.php \\\\\\
$sql="SELECT * FROM sales_queries AS sq INNER JOIN ( SELECT MAX(Query_id) AS mId FROM sales_queries WHERE follow_up BETWEEN '".$s_date."' AND '".$e_date."' GROUP BY nic_id ) AS subsq ON subsq.mId = sq.Query_id";

///////////// QUERY for month_followup.php \\\\\\
$sql="SELECT * FROM sales_queries AS sq INNER JOIN ( SELECT MAX(Query_id) AS mId FROM sales_queries WHERE follow_up > '".$s_date."' GROUP BY nic_id ) AS subsq ON subsq.mId = sq.Query_id";

它运作完美但是当有人在月份页面上查询并在下周给出休息日期时,它会在周和月的两个页面上显示 我想要的是,它只显示一个MAX(Query_id),它在week_followup.php,fornight_followup.php或month_followup.php中。 ONLY MAX(query_id)

1 个答案:

答案 0 :(得分:0)

Forexample 在week_fallowup.php中,日期范围是

s_date = 21/2015年9月

e_date = 28/2015年9月

在fornight_fallowup.php日期范围是

s_date = 29/2015年9月

e_date = 13 / Oct / 2015

在month_fallowup.php中,日期范围是

s_date = 14/2015年9月