您的位置:首页 > 其它

Logging Services 简介

2011-10-17 14:58 176 查看
select distinct userpo1_.ID as ID60_, userpo1_.CUST_ID as CUST2_60_, userpo1_.CARD_TYPE as CARD3_60_, userpo1_.USER_CODE as USER4_60_, userpo1_.LOGIN_PASS as LOGIN5_60_, userpo1_.LOGIN_NAME as LOGIN6_60_, userpo1_.USER_NAME as USER7_60_, userpo1_.GENDER as GENDER60_, userpo1_.CARD_CODE as CARD9_60_, userpo1_.IDENTITY as IDENTITY60_, userpo1_.TEL1 as TEL11_60_, userpo1_.TEL2 as TEL12_60_, userpo1_.REC_FLAG as REC13_60_, userpo1_.CHK_FLAG as CHK14_60_, userpo1_.OPT_TYPE as OPT15_60_, userpo1_.OPT_USERID as OPT16_60_, userpo1_.CHK_USERID as CHK17_60_, userpo1_.LASTUPDATE as LASTUPDATE60_, userpo1_.TEMP1 as TEMP19_60_, userpo1_.TEMP2 as TEMP20_60_ from RUN08110.T_ACCUSR accountuse0_, RUN08110.T_USRINFO userpo1_, RUN08110.T_CUSTOMER customerpo2_ where userpo1_.CUST_ID=customerpo2_.ID and accountuse0_.USER_ID=userpo1_.ID and accountuse0_.CHK_FLAG>0 and userpo1_.IDENTITY>3 and (customerpo2_.CUST_CODE like '%0000000009%') and userpo1_.IDENTITY=7 and accountuse0_.REC_FLAG=1 fetch first 10 rows only
就是这么一个由Hibernate转换出来的SQL语句 在IBM AS400数据库中执行就出现了问题,问题是由于有了fetch以后distinct失效了,本来这条语句的目的是先distinct取出不重复的记录,然后从不重复的记录中取出前面的10条记录,但是在AS400中执行以后结果却取出了重复的结果,其实就是distinct失效了。我认为这应该算这个数据库产品的一个BUG,后来我也解决了问题。解决问题的方法是改写了上面这条语句,先用户distinct取出了不重复的记录,语句变成这样的了:
select * from run08110.T_USRINFO where id in(select distinct userpo1_.ID as ID60 from RUN08110.T_ACCUSR accountuse0_, RUN08110.T_USRINFO userpo1_, RUN08110.T_CUSTOMER customerpo2_ where userpo1_.CUST_ID=customerpo2_.ID and accountuse0_.USER_ID=userpo1_.ID and accountuse0_.CHK_FLAG>0 and userpo1_.IDENTITY>3 and (customerpo2_.CUST_CODE like '%0000000009%') and userpo1_.IDENTITY=7 and accountuse0_.REC_FLAG=1) fetch first 10 rows only
也就是先用子查询找到不重复的记录,然后再从不重复的记录中取出10条,问题得到解决了,而且查询速度得到了大幅的提升。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: