我需要将SQL转换为Transbase

时间:2015-04-01 18:56:49

标签: mysql database transbase

我需要将SQL转换为transbase,因为当我在Transbase中使用下面的脚本时,我得到一个非常难看的错误。

我的剧本:

SELECT  STR_ID, TEX_TEXT AS STR_DES_TEXT,   IF( EXISTS( SELECT * FROM   tof_SEARCH_TREE AS SEARCH_TREE2
  WHERE SEARCH_TREE2.STR_ID_PARENT <> tof_SEARCH_TREE.STR_ID
  ), 1, 0) AS DESCENDANTS
  FROM  tof_SEARCH_TREE
  INNER JOIN tof_DESIGNATIONS ON DES_ID = STR_DES_ID
  INNER JOIN tof_DES_TEXTS ON TEX_ID = DES_TEX_ID
WHERE   STR_ID_PARENT <> NULL AND   DES_LNG_ID = 21 AND EXISTS (
SELECT * FROM tof_LINK_GA_STR 
  INNER JOIN tof_LINK_LA_TYP ON LAT_TYP_ID = 3822 AND LAT_GA_ID = LGS_GA_ID
  INNER JOIN tof_LINK_ART ON LA_ID = LAT_LA_ID
WHERE   LGS_STR_ID = STR_ID
);

我的错误是:

  

编译错误:&#39;)&#39;预期:在线&gt; 2&lt;:   从tof_SEARCH_TREE AS SEARCH_TREE2

1 个答案:

答案 0 :(得分:1)

我没有使用过Transbase,但它声称支持ANSI SQL功能。 if()不是ANSI函数,因此您可以尝试:

SELECT STR_ID, TEX_TEXT AS STR_DES_TEXT,
       (CASE WHEN EXISTS (SELECT 1
                          FROM tof_SEARCH_TREE AS SEARCH_TREE2
                          WHERE SEARCH_TREE2.STR_ID_PARENT <> tofSEARCH_TREE.STR_ID
                         )
             THEN 1 ELSE 0
        END) AS DESCENDANTS
FROM tof_SEARCH_TREE INNER JOIN
     tof_DESIGNATIONS
     ON DES_ID = STR_DES_ID INNER JOIN
     tof_DES_TEXTS
     ON TEX_ID = DES_TEX_ID
WHERE STR_ID_PARENT IS NOT NULL AND
      DES_LNG_ID = 21 AND
      EXISTS (SELECT 1
              FROM tof_LINK_GA_STR INNER JOIN
                   tof_LINK_LA_TYP
                   ON LAT_TYP_ID = 3822 AND LAT_GA_ID = LGS_GA_ID INNER JOIN
                   tof_LINK_ART
                   ON LA_ID = LAT_LA_ID
              WHERE LGS_STR_ID = STR_ID
             );

我认为这符合ANSI标准。而且,它也适用于MySQL。