开发者

How to order by a count(*) field?

开发者 https://www.devze.com 2023-03-26 03:23 出处:网络
I have a MySQL query like this: SELECT xid, count(yid) AS tot FROM x_y_map WHERE z=11 GROUP BY xid ORDER BY tot

I have a MySQL query like this:

SELECT xid, count(yid) AS tot
FROM x_y_map
WHERE z=11
GROUP BY xid
ORDER BY tot

The table is just a simple mapping of X's to Y's. Without the ORDER BY the query appears to work and displays the number of Y's each X has - one row for each X. However, adding the ordering, all I 开发者_JAVA技巧get is:

xid     yid
0       36503

Why is this happening, and how do I get the ordered list?


try direct count in order by like that:

ORDER BY count(yid)


On further research it looks like this is a bug in PHPMyAdmin. Running the same query through PHP gets the correct result. I think PMA is tripping up over so many rows for some reason.

0

精彩评论

暂无评论...
验证码 换一张
取 消