Home  >  Q&A  >  body text

mysql - SQL语句使用聚合函数之后有些字段没有分组显示,那它显示的规则是什么?

ringa_leeringa_lee2743 days ago843

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-04-17 13:46:49

    Will the field hk.backMoney display the data corresponding to the largest hk.backTime?

    Because you used Group By, the largest hk.backTime under the same userInfoId is displayed

    After using aggregate functions on multiple fields, if the other fields are not grouped, there will only be one. How are the other fields obtained?

    The method of selecting other fields is related to the specific implementation of the database you use. It may be sorted by default or returned randomly, so generally speaking, Select non-aggregated fields are meaningless in aggregate queries. If you want to achieve something like retrieving a user's most recent operation record, you need to wrap another layer of query statements outside.

    reply
    0
  • Cancelreply