假設我有以下內容的表:MySQL的GROUP BY子句驗證
mysql> select * from test;
+----+------+
| id | val |
+----+------+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 1 |
| 5 | 2 |
| 6 | 2 |
| 7 | 2 |
| 8 | 2 |
+----+------+
8 rows in set (0.00 sec)
mysql>
現在我運行錯誤的SQL查詢與group by
條款並沒有對id
列中的任意聚集和得到錯誤的結果:
mysql> select id, val from test group by val;
+----+------+
| id | val |
+----+------+
| 1 | 1 |
| 5 | 2 |
+----+------+
2 rows in set (0.00 sec)
mysql>
可以mysql客戶端或可能一些其他工具驗證此查詢,併發出錯誤或警告使用group by
沒有聚合?
+1關注此 – 2013-03-08 12:03:24