没有group by子句,只返回1条记录;其中,返回所需的记录数
SELECT
PM.id AS id, PM.email AS email, PM.name AS name, PM.mobile AS mobile,
PM.country AS country, PM.status AS status, PM.cdate AS joined_date,
PM.details_status AS details_status, PM.freeze AS freeze, PM.blacklist AS blacklist,
PM.blacklist_remark AS blacklist_remark, PM.blacklist_adate AS blacklist_adate,
MA.m_app_id AS app_id, MA.full_name AS replace_name, MAX(MA.ldate) AS ldate,
MA.service_type AS svc_type
FROM whatever_db.tw_person_merchant PM
LEFT JOIN (
whatever_db.tw_person_merchant PMM
INNER JOIN
whatever_db.tw_merchant_application_details MA
ON PMM.app_id = MA.m_app_id
INNER JOIN
whatever_db.tw_merchant_application MAP
ON MA.m_app_id = MAP.id
AND MAP.status NOT IN ('10' , '60')
AND MA.id = (SELECT max(id) FROM whatever_db.tw_merchant_application_details WHERE m_app_id = PMM.app_id )
) ON PM.app_id = MA.m_app_id
WHERE PM.details_status IN ('90', '0')
AND PM.blacklist = 0
AND PM.name != ''
-- **here, without the group by clause, the result is just 1 record
GROUP BY PM.id
ORDER BY PM.id DESC
我正在测试sql脚本是否有相关商家返回,但中间只显示1条记录,经过反复试验,插入的“group by”解决了这个问题。但这个“group by”不是总结,而是显示比没有它更多的结果。意想不到的结果和如此背叛理智的行为。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号