我必须将使用oracle数据库的系统更改为PostgreSQL。 以下查询在PostgreSQL查询构建器中运行时返回“8”,
SELECT COUNT(*)
from database.client c
left join database.salutation t on c.SALUTATIONID = t.SALUTATIONID
left join database.add_details ad on ad.ADDDETAILID = c.ADTYPEID
left join database.add_type at on at.ADDTYPEID = ad.ADDTYPEID
left join database.geo_cat g on g.GEOID = ad.POSCODEID
left join database.cltype clt on clt.CLTYPE = '<CLIENTTYPE>'
inner join database.mapclient mc
on mc.CLIENTID = c.CLIENTID
and mc.CLTYPEID = clt.CLTYPEID
and mc.EFFDATE <= '06-JUN-2014'
在java类中,查询执行如下
Query queryCount = getSession().createSQLQuery(countSql);
int count = ((Number) queryCount.uniqueResult()).intValue();
这适用于Oracle,但对于Postgre,它会出现以下错误,
查询未返回唯一结果:8
为什么会发生这种情况?我能为此做些什么?
答案 0 :(得分:0)
尝试将select子句更改为:
SELECT COUNT(c.id) from database.client c