Multi-table join query the database using the group by the grouping of statements, Expression # 1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'XXX' which is not functionally dependent on columns in GROUP BY claus

Description of Requirement:

  If the joint inquiry with two tables, and the results of the query are grouped: sql as follows:

    

 1 SELECT
 2 a.`id`,
 3 a.`fr_num`,
 4 b.`ent_status`
 5 FROM
 6 `table1` a
 7 LEFT JOIN `table2` b
 8 ON b.`fr_id` = a.`id`
 9 GROUP BY b.`fr_num`

  This sql statement error results are as follows:

  Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'a.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by.

  Problem:

  First, look at the group by sql usage:

  1, the latter either in the query field select group by, or is a function of the polymerization

  2, if the conditions of the screening results, there are two ways: (1) where + first use condition and use the group by (2) using the first group by, and then use the having screening results

  Resolution: The combined use of the group by sql improve the ok ~

Guess you like

Origin www.cnblogs.com/javalively/p/11724565.html