分享到:
发表于 2008-12-18 10:48:50 楼主 | |
select id,username,count(username) as total from user group by username having username='李阳' order by id desc; 结果显示 3 个李阳 select id,username,count(username) as total from user where username='李阳' group by username order by id desc; 结果显示 2 个李阳 select username from user where username='李阳' 结果显示 2 个李阳 这是咋回事? |
|
楼主热贴 |
发表于 2008-12-18 10:48:50 1楼 | |
你的表结构整出来吧。 |
|
个性签名:
|
发表于 2008-12-18 10:48:50 2楼 | |
username varchar(30) id为主键 跟表结构有关系吗? |
|
发表于 2008-12-18 10:48:50 3楼 | |
CREATE TABLE `user`(`ID` SMALLINT NOT NULL Auto_Increment Primary key, `UserName` VARCHAR(40) NOT NULL DEFAULT '' )ENGINE='InnoDB' CHARSET='UTF8' Collate `UTF8_General_CI` select id,username,count(username) AS total from user group by username having username='李阳' order by id DESC select id,username,count(username) AS total from user WHERE username='李阳' group by username order by id DESC 得到的纪录都是2条 |
|
发表于 2008-12-18 10:48:50 4楼 | |
哈哈,知道为什么了 select id,username,count(username) AS total from user WHERE username regexp '李阳' group by username order by id DESC 结果为2条 //正确的 select id,username,count(username) AS total from user group by username having username='李阳' //或者username regexp '李阳' order by id DESC 结果为3条 //错误的 不过问题是having 难道用regexp不行吗 |
|
针对ZOL星空(中国)您有任何使用问题和建议 您可以 联系星空(中国)管理员 、 查看帮助 或 给我提意见