0

我需要将 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
);

我的错误是:

编译错误:')' 预期:在 >2<: FROM tof_SEARCH_TREE AS SEARCH_TREE2

4

1 回答 1

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 中工作。

于 2015-04-01T19:39:35.373 回答