背景

SELECT
	t1.page_role,
	t2.page_id,
	t2.config,
	t2.style 
FROM
	t_page t1
	LEFT JOIN t_page_new_content t2 ON t1.id = t2.page_id 
WHERE
	t1.can_recommend = 1 
	AND t2.page_id IN (10758,10757,10761)
	AND t2.style IN ( 'img_tag_text', 'billboard', 'head_img_list' ) 
	AND ( ( start_time <= NOW( ) AND end_time > NOW( ) ) OR permanent = 1 ) 
	GROUP BY t2.page_id
	LIMIT 3

t2.page_id 是主键或者唯一键时,这个语句就是合法的,不管sql_mod是不是 ONLY_FULL_GROUP_BY

阿里云配置

_config.yml

_config.yml

参考

1.关于MySQL中only_full_group_by模式的一点个人理解 2.The query is valid if name is a primary key of t or is a unique NOT NULL column

原创文章转载请注明出处: select中既有聚合字段,又有非聚合字段