0

我有两个如下表。

句子

     +--------+----------+-----------------------------------------------------------------------+
     | id     | language | text                                                                  |
     +--------+----------+-----------------------------------------------------------------------+
     | 519125 | epo      | Mia onklo aĉetis por mi horloĝon kiu estas tre akurata.               |
     | 519126 | epo      | Mi ne povas akcepti vian donacon.                                     |
     | 519127 | uig      | ئۇ پۈتۈن مەملىكەتنى ئارىلاپ چىقماقچى.                                   |
     | 519128 | eng      | She's planning to travel the entire country.                          |
     | 519129 | eng      | He's planning to travel the entire country.                           |
     | 519130 | uig      | تاڭنىڭ ئالدىدا قاراڭغۇسى بار.                                          |
     | 519131 | epo      | Li trovas kritikindan en ĉio kion mi faras.                           |
     +--------+----------+-----------------------------------------------------------------------+

链接

     +------------+--------------+
     | sentenceId | translatedId |
     +------------+--------------+
     |     124665 |      1972285 |
     |     124666 |       279328 |
     |     124666 |       957578 |
     |     124667 |       279327 |
     |     124667 |       440607 |
     +------------+--------------+

它们由数百万行组成。我想在第二个表之后再添加两列,sentenceId如下translatedId所示:

       +------------+-------------+--------------+-------------+
       | sentenceId | languageId1 | translatedId | languageId2 |
       +------------+-------------+--------------+-------------+

在上表中(sentenceId languageId1)(translatedId languageId2)确实是一对。languageId1并分别显示和languageId2的语言简写。但是在语言列的第一个表中定义了sentenceId 和translatedId 的语言简写。为了形成该表,必须在第一个表中查找每个和 translateId 值,并且必须在and中替换找到的语言简写。那么我怎样才能形成上表呢?sentenceIdtranslatedIdsentenceIdlanguageId1languageId2

4

1 回答 1

1

这会将您的结果添加到一个新表中(您需要先创建它)

INSERT INTO mynewtable 
SELECT LINKS.sentenceId, SRC_SENT.language AS srcLanguage,
       LINKS.translatedId, DST_SENT.language AS dstLanguage
FROM LINKS
INNER JOIN sentences SRC_SENT ON (LINKS.sentenceId = SRC_SENT.id)
INNER JOIN sentences DST_SENT ON (LINKS.translatedId = DST_SENT.id)

如果要在表链接中添加列,则必须先修改其结构,然后再对其进行更新。

于 2013-10-15T10:17:52.997 回答