如何解决mysql复杂的查询? [英] how to solve mysql Complex QUERY?

查看:32
本文介绍了如何解决mysql复杂的查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考我之前的问题.

如何进一步过滤GROUP BY记录在mysql中?有三个不同的页面,我将在其中使用相同的查询但具有不同的日期,如下所示:在week_fallowup.php 中的日期范围是

How to further filter GROUP BY record in mysql? There are three different pages where i will use same query but with different dates as shown below: In week_fallowup.php date range is

s_date= 21/Sept/2015

s_date= 21/Sept/2015

e_date= 28/Sept/2015

e_date= 28/Sept/2015

在 fornight_fallowup.php 中的日期范围是

In fornight_fallowup.php date range is

s_date= 29/Sept/2015

s_date= 29/Sept/2015

电子日期= 2015 年 10 月 13 日

e_date= 13/Oct/2015

在month_fallowup.php 中的日期范围是

In month_fallowup.php date range is

s_date= 14/Sept/2015

s_date= 14/Sept/2015

有三个后续页面 Week_followup.php、Fornight_followup.php &Month_followup.php,因为我使用了以下三个查询:

There are three followup pages Week_followup.php, Fornight_followup.php & Month_followup.php in that i am using below three queries:

/////////////   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.仅 MAX(query_id)

It works perfectly but when someone fallow query on month page and give date of fallowup in next week, it shows on both pages week and month what i want is, it show only one MAX(Query_id) either it is in week_followup.php, fornight_followup.php or month_followup.php. ONLY MAX(query_id)

推荐答案

例如在week_fallowup.php 中的日期范围是

Forexample In week_fallowup.php date range is

s_date= 21/Sept/2015

s_date= 21/Sept/2015

e_date= 28/Sept/2015

e_date= 28/Sept/2015

在 fornight_fallowup.php 中的日期范围是

In fornight_fallowup.php date range is

s_date= 29/Sept/2015

s_date= 29/Sept/2015

电子日期= 2015 年 10 月 13 日

e_date= 13/Oct/2015

在month_fallowup.php 中的日期范围是

In month_fallowup.php date range is

s_date= 14/Sept/2015

s_date= 14/Sept/2015

这篇关于如何解决mysql复杂的查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆