+----+------+-------+
| 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)
请高手赐教!!!
6 个解决方案
#1
group是SQL语法的关键字,换成其他的如_group
#2
如楼上所言。
#3
select max(group) from dz_user group by group
#4
select max(`group`) from dz_user;
#5
哎!我居然忽略这个问题了!!谢谢啊
#6
恩,改了列明就没问题了呢
mysql> select max(groupzb) from dm_user;
+--------------+
| max(groupzb) |
+--------------+
| 8 |
+--------------+
1 row in set (0.02 sec)
#1
group是SQL语法的关键字,换成其他的如_group
#2
如楼上所言。
#3
select max(group) from dz_user group by group
#4
select max(`group`) from dz_user;
#5
哎!我居然忽略这个问题了!!谢谢啊
#6
恩,改了列明就没问题了呢
mysql> select max(groupzb) from dm_user;
+--------------+
| max(groupzb) |
+--------------+
| 8 |
+--------------+
1 row in set (0.02 sec)