日期:2014-05-17  浏览次数:20973 次

group by
select   max(reg_time),a.username,a.userinfo,a.coname,b.tel,b.fax,b.count   from   a,b   where   a.usr_id=b.usr_id   group   by   a.kind


服务器:   消息   8120,级别   16,状态   1,行   1
列   a.username   在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在   GROUP   BY   子句中。

怎么解决这中错误!!!
a.kind    int型 值为1,2,3
我要的目的是 按a.kind排序 1,2,3分组; 查出的记录,要把3的记录在前面显示.
GROUP   BY必须是 有聚合函数
但是我要显示更多的字段 那每个条件都加聚合啊?
综述::就是我要多字段显示,按照a.kind分组排序 请大家帮忙!!
谢谢!!


------解决方案--------------------
你的 a.username 不在 GROUP BY 子句内,当让不能输出

select max(reg_time),a.username,a.userinfo,a.coname,b.tel,b.fax,b.count from a,b where a.usr_id=b.usr_id group by a.username,a.kind........