ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'yatest.user2.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
检查一下你的 select 的字段 ,取消里面不能分组的字段。
謝謝 江南一號的回覆與解釋
我不明白的是,套以下的函示寫出你說的 " select status, count(*) from user where id<=10 group by status " 該怎麼寫?
是 print_r($PdoMySQL->find($tables,'id>=5','count(*)','status'));會出現錯誤
還是需要修改ParsFields函式?如何改?抱歉阿,我真的還是基礎班的....
public static function find($tables,$where=null,$fields='*',$group=null,$having=null,$order=null,$limit=null){ $sql='SELECT ' .self::parseFields($fields).' FROM '.$tables .self::parseWhere($where) .self::parseGroup($group) .self::parseHaving($having) .self::parseOrder($order) .self::parseLimit($limit); $dataAll=self::getAll($sql); return count($dataAll)==1?$dataAll[0]:$dataAll; // 三元運算子 } public static function parseFields($fields){ // 如是數組/陣列 if(is_array($fields)){ array_walk($fields,array('PdoMySQL','addSpecialChar')); // array_walk() 回調函式 $fieldsStr=implode(',',$fields); // 如是字串 }elseif(is_string($fields)&&!empty($fields)){ if(strpos($fields,'`')===false){ $fields=explode(',',$fields); array_walk($fields,array('PdoMySQL','addSpecialChar')); $fieldsStr=implode(',',$fields); }else{ $fieldsStr=$fields; } }else{ $fieldsStr='*'; } return $fieldsStr; }
出現一樣的問題,當執行這句 print_r($PdoMySQL->find($tables,'id<=10','*','status'));
出現這樣的錯誤訊息:
SQLSTATE : 42000
SQL Error : Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'imooc.user.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
Error SQL : SELECT * FROM user WHERE id<=10 GROUP BY status
江南1号所說的“检查一下你的 select 的字段 ,取消里面不能分组的字段”不太懂該怎麼做....求解,感謝先~