簡體   English   中英

將SQL查詢轉換為HQL

[英]converting SQL query to HQL

我需要將此SQL查詢轉換為HQL

select
        * 
    from
        ( select
            routemaste0_.ROUTE_ID as col_0_0_,
            routemaste0_.ROUTE_CODE as col_1_0_,
            routemaste0_.START_PLACE_ID as col_2_0_,
            routemaste0_.END_PLACE_ID as col_3_0_,
            routemaste0_.IS_ACTIVE as col_4_0_,
            routemaste0_.LINKED_ROUTE as col_5_0_
        from
            OPRS_ROUTE_MASTER routemaste0_
            inner join OPRS_ROUTE_HALTS routehalts0_
                 on routemaste0_.route_id = routehalts0_.route_id
        where routehalts0_.PLACE_ID = '51'
        order by
            routemaste0_.ROUTE_ID ASC  )

我這樣嘗試

SELECT    rm.id , 
          rm.routeCode , 
          rm.startPlaceId , 
          rm.endPlaceId , 
          rm.active , 
          rm.linkedRoute 
FROM      RouteMaster rm  
          INNER JOIN  rm.routeHalts AS rh 
WHERE     rm.id = rh.routeId  
          AND  rh.placeId = :PlaceId  
ORDER BY  rm.id  ASC

但沒有得到預期的結果。 我擔心的是,我需要inner join on條件執行inner join on聯接。

有人能幫我嗎

我認為問題的原因可能是route_id不是任何表中的主鍵。 因此,我建議您在這種情況下嘗試Theta風格的連接:

SELECT  rm.id , rm.routeCode , rm.startPlaceId , rm.endPlaceId , rm.active, rm.linkedRoute 
FROM RouteMaster rm, RouteHalts rh
WHERE rm.routeId = rh.routeId AND rh.placeId = :PlaceId  
ORDER BY  rm.id  A

在HQL查詢的變體中,where條件中不需要rm.id = rh.routeId部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM