Home > database > Mysql group by query fields without aggregation function, is how to keep?
Mysql group by query fields without aggregation function, is how to keep?
Time:09-28
As title, if there is a table in the mysql database table, field respectively. A, b, c, d, think according to field a group, and then display the first line of each group, the SQL statement format for: select a, MIN (b), c, d from table group by a, The SQL query result set, b fields can take to the minimum, then c and d field is take?
the data contentA b c d 1 1 1 1 1 2 2 2 3 3 3 1
Above data content directly from the mysql database query, result sets: 1,1,1,1, but from the inside of the code query, return a result set is: 1,1,3,3,
Ask god to reassure!!!!!!
CodePudding user response:
Select a, MIN (b), MIN (c), MIN (d) from the table group by a
CodePudding user response:
According to the group by the result of a process focus on the first line of the first line is the first line, according to the order of physical storage is unpredictable, random After the group by data, context switches for each group instead of each line, as a result, the standard SQL, the select list can't use the grouping field, because the violation of the relational model paradigm, In mysql, extension of standard SQL GROUP BY (in other words, in violation of the relational model paradigm), can use the grouping field in the select field list, http://www.cnblogs.com/f-ck-need-u/p/8656828.html