gpt4 book ai didi

php - 如何进一步过滤mysql中的GROUP BY记录?

转载 作者:可可西里 更新时间:2023-11-01 08:44:24 25 4
gpt4 key购买 nike

请检查我想要查询 ID“43”的完整行(以及另一个 nic_id max query_id 行)的图像,但它只给我最大 query_id,我尝试了不同的查询,例如:

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`

当客户再次访问时,使用不同主题的相同 nic_id 进行跟进增加 (+1)。  only one customer data in table

我想要完整的 43 行,主题为“Registration4”,日期等

不是这个,应该是 Registration4 date:2015-09-11 enter image description here

最佳答案

类似于this question的答案,您可以使用子查询并加入以获取您想要的结果。类似于以下的内容应该可以工作:

SELECT `Query_id`, `nic_id`, `date`, `subject`, `followup_no`
FROM `sales_queries` AS sq
INNER JOIN (
SELECT MAX(`Query_id`) AS mId
FROM `sales_queries`
GROUP BY `nic_id`
) AS subsq ON subsq.mId = sq.Query_id

关于php - 如何进一步过滤mysql中的GROUP BY记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32517231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com