[转帖]MYSQL grouping result: Invalid use of group function_MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2147 | 回复: 0   主题: [转帖]MYSQL grouping result: Invalid use of group function        下一篇 
刘习托
注册用户
等级:中士
经验:208
发帖:66
精华:0
注册:2011-11-23
状态:离线
发送短消息息给刘习托 加好友    发送短消息息给刘习托 发消息
发表于: IP:您无权察看 2014-11-14 14:20:24 | [全部帖] [楼主帖] 楼主

出现就google,以下文章解决了问题

http://www.sitepoint.com/forums/showthread.php?666125-MYSQL-grouping-result-Invalid-use-of-group-function

MYSQL grouping result: Invalid use of group function

Hi,

I have 3 tables,

- pages (with page id, etc)

- tags (tag id, and tag name)

- tagged (tagged id, tag id, and page id)

this is my SQL query,

Code:

SELECT root_tags.tag_id, root_tags.tag_name, COUNT( root_tagged.pg_id )

FROM root_tags

LEFT JOIN root_tagged ON ( root_tagged.tag_id = root_tags.tag_id )

WHERE root_tagged.pg_id != '0'

GROUP BY root_tags.tag_id

ORDER BY COUNT(root_tagged.pg_id) DESC

LIMIT 0,20

in my localhost, it returns the result I want, such as,

Code:

tag_id     tag_name     COUNT( root_tagged.pg_id )

28     illustration     20

1     typography     15

33     floral     11

3     decorative     11

7     vector     11

36     drawing     9

6     design     9

8     texture     9

16     experimental     9

29     branding     7

31     ornate     7

34     pattern     5

4     editorial     5

37     textured     4

19     packaging     3

35     crest     3

5     advertising     3

30     photo-montage     2

38     symmetry     2

13     line-drawing     2

I want to order the result in the way that higher numbers always comes first on top.

But in my live server, it returns this error message,

MySQL said: Documentation

#1111 - Invalid use of group function

It only works fine when this line below is removed but the result cannot be order where higher numbers always comes first...

Code:

ORDER BY COUNT(root_tagged.pg_id) DESC

any ideas??

many thanks if you can help please...

cheers,

Lau

--转自 北京联动北方科技有限公司




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论