phpr
新手上路

UID 100430
精华
0
积分 15
帖子 9
金钱 15 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2007-11-1
状态 离线
|
[广告]: Enom域名自助付费 自助注册 自助PUSH 主流域名COM等一律57.99元年
哎,没有人理我,经过我多天的研究,还是我自己来回答自己吧,呵呵
1 select id,distinct type from content
这个语句是错误的 因为distinct不可以用在第二个字段上
2 select distinct type,id from content
这个语句不报错,但distinct并没有起到作用
3 select id,group_concat(distinct type) from content group by type
group_concat是应用于mysql4.1版本中的
4 select id,count(distinct type) from content group by type
统计type字段
5 select distinct type,id from content group by type
这句是正确的
distinct在使用中,应注意以下几点:
1.distinct要在第一个字段上使用,不可以放在后面的字段上
2.需要去掉哪个重复的字段,就需要用group by把这个字段,分一下组
3.注意一下mysql的版本,这样一来,distinct就可以使用好了
呵呵
文章引用自:
http://blog.sina.com.cn/ningning33
|  MY BLOG--我的博客
http://blog.sina.com.cn/ningning33 |
|