不使用JOIN关键字的SQL转换(Oracle jpa)

时间:2015-10-26 14:11:43

标签: sql oracle

有没有办法在不使用JOIN关键字的情况下重写以下内容?就像使用旧方法连接表格一样。

SELECT Routes.* FROM Routes
JOIN (SELECT let,dir,min(num) as minnum
      FROM Routes
      GROUP BY let, dir
      ) ld JOIN Routes tt
ON tt.let = ld.let AND tt.dir = ld.dir AND tt.num = ld.minnum 
AND Routes.let = ld.let AND Routes.dir = ld.dir
WHERE tt.ctry = 'CA';

2 个答案:

答案 0 :(得分:0)

这是您正确编写的查询:

SELECT Routes.*
FROM Routes JOIN
     (SELECT let, dir, min(num) as minnum
      FROM Routes
      GROUP BY let, dir
     ) ld
     ON Routes.let = ld.let AND Routes.dir = ld.dir JOIN
     Routes tt
     ON Routes.let = ld.let AND Routes.dir = ld.dir AND tt.num = ld.minnum 
WHERE tt.ctry = 'CA';

您似乎希望最小化let的{​​{1}}和dir的所有路由。我不知道你的数据是什么样的,但这似乎是一个看似合理的等价物:

num

答案 1 :(得分:0)

它不像你在这里有任何艰难的联系。几乎所有你需要做的就是替换“#34; JOIN"使用逗号,并将所有连接条件下推到WHERE子句中。所以这是传统Oracle语法中的确切查询:

SELECT Routes.* 
FROM Routes
   ,(SELECT let,dir,min(num) as minnum
      FROM Routes
      GROUP BY let, dir
      ) ld 
   ,Routes tt
WHERE tt.let = ld.let 
  AND tt.dir = ld.dir 
  AND tt.num = ld.minnum 
  AND Routes.let = ld.let 
  AND Routes.dir = ld.dir
  AND tt.ctry = 'CA';

话虽如此,这肯定不是获得此数据的最有效方式。我跳过表的第三次扫描并使用与Gordon相同的分区分析!