首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Hql技巧积累之一:同时使用distinct和order by的有关问题

2012-08-31 
Hql技巧积累之一:同时使用distinct和order by的问题所用数据库:ms server2000所用hibernate版本: hibernat

Hql技巧积累之一:同时使用distinct和order by的问题
所用数据库:ms server2000
所用hibernate版本: hibernate3.2


sql:

--查询签约年份,不重复,年份降序显示select distinct year(a.signDate) as signYear from my_table aorder by signYear desc

以上sql在查询分析器里是没有问题的。
转换成hql如下:
hql:
select distinct year(a.signDate) as signYear from MyTable aorder by signYear desc

以上hql在服务启动编译时通过, 单执行查询时抛出异常:列名“signYear”无效。

修改成如下hql才行:
select distinct year(a.signDate) as signYear from MyTable aorder by year(a.signDate) desc

以上hql对应的sql也正确。

热点排行