This question already has answers here:
Error related to only_full_group_by when executing a query in MySql
                                
                                    (16个答案)
                                
                        
                                2年前关闭。
            
                    
我无法从列数据中读取记录,为什么?
码:

$_query = mysqli_query($mysqli , "SELECT  o.id,o.surname,o.name,so.data FROM mowcy AS o
          LEFT JOIN zeb AS so ON so.id=o.id AND so.mowca=o.mowca
           WHERE
             o.archiwum = 0
             AND o.id<>1
             AND o.mowca = 3

              GROUP BY o.id
               ORDER BY ISNULL(o.id) desc, MAX(so.data) ")
                or die(mysqli_error($mysqli));


显示错误:


  列表不在GROUP BY子句中,并且包含未聚合的列
  'rafik73_tereny.so.data'在功能上不依赖于
  GROUP BY子句中的列;这与
  sql_mode = only_full_group_by

最佳答案

这样尝试;

SELECT  o.id,MAX(so.data) FROM mowcy AS o
          LEFT JOIN zeb AS so ON so.id=o.id AND so.mowca=o.mowca
           WHERE
             o.archiwum = 0
             AND o.id<>1
             AND o.mowca = 3
              GROUP BY o.id
               ORDER BY ISNULL(o.id) desc, MAX(so.data)


由于在将查询中的内容进行分组时会直接向您显示错误,因此您应该仅选择分组字段和聚合列。

09-19 16:11