首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2ME开发 >

hibernate 如何用别名排序

2012-10-05 
hibernate 怎么用别名排序select a.v_rec_id,a.v_title,(select count(*)fromAnswer as r where r.v_ques

hibernate 怎么用别名排序
"select a.v_rec_id,a.v_title,(select count(*)from Answer as r where r.v_question_rec_id=a.v_rec_id) as val from Ask as a where a.v_flag='0' order by val desc";


09:14:32,781 ERROR JDBCExceptionReporter:78 - Unknown column 'val' in 'order clause'错误 这个要怎么办怎么办怎么办

[解决办法]
你试试这样ok不 
select a.v_rec_id,a.v_title,count(a.v_rec_id) val 
from Ask a,Answer r 
where r.v_question_rec_id=a.v_rec_id 
and a.v_flag='0' 
group by a.v_rec_id
order by val desc
[解决办法]
select a.v_rec_id,
a.v_title,
count(a.v_rec_id) as val
from Ask as a
left join Answer as r
on r.v_question_rec_id = a.v_rec_id
 where a.v_flag = '0'
 group by a.v_rec_id,a.v_title
 order by val desc

热点排行