ofbiz自关联子查询

1,这样的查询SQL如何使用ofbiz实现。
SELECT
*
FROM
bdlyjg_t_gpsinfo T
INNER JOIN (
SELECT
imei,
MAX (uploadtime) AS MaxDate
FROM
bdlyjg_t_gpsinfo
GROUP BY
imei
) tm ON T .imei = tm.imei
AND T .uploadtime = tm.MaxDate
AND t.imei IN (
'956655010000250',
'13518103572'
)
2,解决办法如下:
<view-entity entity-name="GpsImei1" package-name="com.scbdlbs.entity">
   <member-entity entity-alias="tm" entity-name="BdlyjgTGpsinfo"/>
   <alias name="imei" entity-alias="tm" group-by="true"/>
   <alias name="maxDate" entity-alias="tm" function="max" field="uploadtime" col-alias="maxDate"/>
</view-entity>

<view-entity entity-name="GpsImei" package-name="com.scbdlbs.entity">
   <member-entity entity-alias="t" entity-name="BdlyjgTGpsinfo"/>
   <member-entity entity-alias="tm" entity-name="GpsImei1">
      <description>自己关联表</description>
   </member-entity>
   <alias name="imei" entity-alias="tm"/>
   <alias-all entity-alias="t"/>
   <view-link entity-alias="t" rel-entity-alias="tm">
      <key-map field-name="imei" rel-field-name="imei"/>
      <key-map field-name="uploadtime" rel-field-name="maxDate"/>
   </view-link>
</view-entity>

你可能感兴趣的:(ofbiz自关联子查询)