请教 查询结果按重复出现值的次数排序的sql语句
table1:
id department event dateTime
1 A sth. t1
2 B sth. t2
3 C sth. t3
4 A sth. t4
5 A sth. t5
6 D sth. t6
7 C sth. t7
. . . .
. . . .
N N sth. tN
查询结果按a、b、c、d...n..的出现次数由大到小排序
请教应该如何写sql语句?
问题点数:20、回复次数:6Top
1 楼mathematician(数学家)回复于 2005-08-02 09:52:32 得分 20
SELECT * from table1 GROUP by department ORDER by COUNT(*) DESC;Top
2 楼ntem(失措)回复于 2005-08-02 11:27:53 得分 0
谢谢数学家,
mySql下出错,提示: Invalid use of group functionTop
3 楼ntem(失措)回复于 2005-08-02 11:42:53 得分 0
我用:
SELECT *, COUNT(department) as d_count from table1 GROUP BY department ORDER BY d_count DESC;
可以按department出现次数排序,但在结果里重复的department没有全部列出,只列出一个
Top
4 楼cnlaomo()回复于 2005-08-05 17:02:10 得分 0
表为什么要这样设计呢?把department字段提出来单独放一个表里面不是简单多了吗?Top
5 楼mathematician(数学家)回复于 2005-08-08 09:56:25 得分 0
ntem (失措):
SELECT * from table1 GROUP by department ORDER by COUNT(*) DESC;
在MYSQL5.0下测试通过。Top
6 楼ntem(失措)回复于 2005-08-10 14:13:05 得分 0
to 数学家:
请问有mysql4.1下的解决方案么?
不行的话就只能5.0了Top




