2016-04-30 27 views
11

15.10から16.04に私のubuntuをアップグレードしたときyii2プロジェクトでこのエラーが発生しましたSQLSTATE [42000]:構文エラーまたはアクセス違反:1055 SELECTリストの式#3がGROUP BY句に含まれておらず、集約されていません

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #3 
of SELECT list is not in GROUP BY clause and contains nonaggregated column 
'iicityYii.opportunity_conditions.money' which is not functionally dependent 
on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 

実行されているSQLをした

私の問題を解決する方法を
SELECT SUM(oc.money),op.id,oc.money, 
      op.mantaghe, 
      op.`time`, op.`id`, `op`.`logo`, 
      `pd`.`user_id`, `op`.`name`, 
      `pd`.`co_name`, `op`.`address`, 
      `op`.`project_type_id`, `op`.`state_id` 
FROM `opportunity` op 
INNER JOIN `profile_details` pd ON op.user_id=pd.user_id 
INNER JOIN `opportunity_conditions` oc ON op.id=oc.opportunity_id 
GROUP BY `op`.`id` 
ORDER BY `op`.`id` DESC 

答えて

3

集計関数の合計と列名のセットを選択した場合、エラーはgroup by句の列名の正しいリストを指定しなかったことを示します。あなたはおそらく、あなたはすべての列

sum(opportunity.id), sum(opportunity_conditions.money), 

合計(機会に合計を追加する必要があります合計必要がある場合は,(opportunity.id),(opportunity_conditions.money), (opportunity.mantaghe),なぜ()にも持ってprofile_details, opportunity_conditionsテーブル

に関連して、グループ内の複数のカラム名を追加する必要がある可能性があります。 THESは通常の列であればmantaghe)、

そうでなければ、()

opportunity.id, opportunity_conditions.money,opportunity.mantaghe,

せずに通常のsintaxを使用する必要があります

私は(私は願っています)を必須カラム名にして、グループで可能なクエリ

SELECT SUM(opportunity_conditions.money), 
     `opportunity`.`id`, 
     `opportunity_conditions.money`, 
     `opportunity.mantaghe`, 
     `opportunity`.`time`, 
     `opportunity`.`logo`, 
     `profile_details`.`user_id`, 
     `opportunity`.`name`, 
     `profile_details`.`co_name`, 
     `opportunity`.`address`, 
     `opportunity`.`project_type_id`, 
     `opportunity`.`state_id` 
FROM `opportunity` 
INNER JOIN `profile_details` ON `opportunity`.`user_id`= `profile_details`.`user_id` 7 
INNER JOIN `opportunity_conditions` ON `opportunity`.`id`=`opportunity_conditions`.`opportunity_id` 
GROUP BY`opportunity`.`id`, `profile_details`.`user_id`,`opportunity_conditions.money`, 
ORDER BY `opportunity`.`id` DESC 

を書き換えしようとしてい

GROUP BY`opportunity`.`id`, `profile_details`.`user_id`,`opportunity_conditions.money`, 
23

か、単にファイル名を指定して実行

$ sudoをmysqlの-u root -p

MySQLサーバインスタンスのSQLモードを変更してください

mysql > SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); 

別の方法は、それが声明 のsql_modeを追加 [mysqldを]と右下のため

  • は、セクションを追加したMySQLのconfigs

    を/etc/mysql/my.cnfに行く使用されるだろう= ""
  • は、MySQLサービス $ sudoをsystemctl再起動mysqlの
+0

ありがとう、ありがとう。 – Stephen

+0

それは私のためにも働いた。ありがとう – manian

+0

ロールバックするには? – abenevaut

0

Tを再起動しますhx、これは私に役立ちましたが、これは設定されませんPERMANENTLY、それは再起動するたびに元に戻ります。

設定ファイル:変更は、MySQLの再起動後に有効に残るように

だから、([mysqld]セクションには例えば/etc/mysql/my.cnf)configファイルでこれを設定する必要があります。 /etc/mysql/my.cnf

[mysqld] 
sql-mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION" 
関連する問題