MySql怎样获取一列中最大值??
mysql> select * from dm_user;
+----+------+-------+
| id | name | group |
+----+------+-------+
| 1 | 张三 | 08 |
| 2 | 李四 | 05 |
| 3 | 王五 | 02 |
| 4 | 赵六 | 01 |
| 5 | 麻七 | 01 |
| 6 | 测试 | 06 |
| 7 | 这样 | 06 |
+----+------+-------+
7 rows in set (0.03 sec)
想查询出group中最大的值,语句:select max(group) from dz_user;
报错信息如下:
mysql> mysql>select max(group) as maxid from dm_user;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'mysql
>select max(group) as maxid from dm_user' at line 1
mysql>
数据表结构如下:
mysql> describe dm_user;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(50) | YES | | NULL | |
| group | int(11) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
请高手赐教!!!
------解决方案--------------------group是SQL语法的关键字,换成其他的如_group
------解决方案--------------------如楼上所言。
------解决方案--------------------select max(group) from dz_user group by group
------解决方案--------------------select max(`group`) from dz_user;