以下のテーブルを使用しています。
mysql> select * from users; +---------+ | name | +---------+ | tanaka1 | | 123 | | qwer | +---------+ 3 rows in set (0.00 sec)
次に↓のクエリを送信したら、成功しました。
mysql> select name, rand(0), round(rand(0)) from users; +---------+---------------------+----------------+ | name | rand(0) | round(rand(0)) | +---------+---------------------+----------------+ | tanaka1 | 0.15522042769493574 | 0 | | 123 | 0.620881741513388 | 1 | | qwer | 0.6387474552157777 | 1 | +---------+---------------------+----------------+ 3 rows in set (0.00 sec)
しかし、 round(rand(0))でgroup byしようとすると失敗してしまいます。
mysql> select name, rand(0), round(rand(0)) from users group by round(rand(0)); ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'y.users.name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
select name, rand(0), round(rand(0)) from users group by name; は成功します。
mysqlのバージョンは5.7.21です。
解決策を教えていただけないでしょうか。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/08/01 06:54
2022/08/02 00:15