[php] ¿Cómo filtrar aún más el registro GROUP BY en mysql?


Answers

Estoy utilizando debajo de tres consultas en tres páginas diferentes. Quiero que IF MAX ( Query_id ) no esté disponible en un rango específico de fechas y luego lo ignore.

/////////////   QUERY 1  \\\\\\\\\\\\\\\\\\\\\

$ sql = "SELECCIONAR * FROM sales_queries AS sales_queries (SELECCIONAR MAX ( Query_id ) AS mId DE sales_queries WHERE follow_up > '". $ s_date. "' GROUP BY nic_id ) AS subsq ON subsq.mId = sq.Query_id";

///////////// QUERY 2 \\\\\\\\\\

$ sql = "SELECCIONAR * FROM sales_queries AS sales_queries (SELECCIONAR MAX ( Query_id ) AS mId DE sales_queries DONDE follow_up ENTRE '". $ s_date. "' Y '". $ e_date. "' GROUP BY nic_id ) AS subsq ON subsq .mId = sq.Query_id ";

///////////// QUERY 3 \\\\\\\\\\

$ sql = "SELECCIONAR * FROM sales_queries AS sales_queries (SELECCIONAR MAX ( Query_id ) AS mId DE sales_queries DONDE follow_up ENTRE '". $ s_date. "' Y '". $ e_date. "' GROUP BY nic_id ) AS subsq ON subsq .mId = sq.Query_id ";

Question

Por favor, compruebe las imágenes, quiero el ROW completo del ID de consulta "43" (y con otra fila nic_id max query_id) pero me da solo max query_id, probé con diferentes consultas para-ejemplo:

SELECT `Query_id`, `nic_id`, `date`, `subject`, `followup_no`, MAX(Query_id) as queryid FROM `sales_queries` GROUP BY `nic_id` HAVING MAX(`Query_id`)

SELECT `Query_id`, `nic_id`, `date`, `subject`, `followup_no`, MAX(Query_id) as queryid FROM `sales_queries` WHERE  GROUP BY `nic_id` HAVING MAX(`Query_id`)

SELECT  `Query_id`, `nic_id`, `date`, `subject`, `followup_no`, MAX(Query_id) as mxqueryid    FROM `sales_queries`WHERE `Query_id` = (SELECT MAX(`Query_id`) FROM `sales_queries`) GROUP BY `nic_id` 

cuando el cliente vuelva a visitar el seguimiento, aumente (+1) con su mismo nic_id con un tema diferente.

Quiero completar 43 filas con el tema "Registration4", fecha, etc.

NO ESTO, debe ser Fecha de registro4: 2015-09-11




Related