1

我有以下查询

SELECT dictionaryEncryptedIndex, filelocation FROM  `DictionaryTable`
 WHERE  `dictionaryEncryptedWord` LIKE '0x0E6E'";

在 c# 中,我循环遍历上述查询的结果,并且对于每个循环迭代,我使用以下查询来获取最终结果:

SELECT * FROM  `MaskedIndexTable` 
 WHERE  `maskedIndexEncryptedIndex`
  LIKE '" + dictionaryEncryptedIndexFROMABOVEQUERY + "'
   AND `fileLocation` = '" + filelocationFROMABOVEQUERY + "'";

dictionaryEncryptedIndex 和 maskedIndexEncryptedIndex 之间的关系不是一对一的关系。

有谁知道如何在一个可以在 Microsoft Access 中使用的 SQL 查询中执行上述操作?

我尝试了多种方法,例如:

SELECT  * from DictionaryTable, MaskedIndexTable
  WHERE MaskedIndexTable.maskedIndexEncryptedIndex = DictionaryTable.dictionaryEncryptedIndex 
    AND  MaskedIndexTable.fileLocation =DictionaryTable.fileLocation
    AND `dictionaryEncryptedWord` LIKE '0x0E6E' 


SELECT dictionaryEncryptedWord, DictionaryTable.filelocation
  FROM DictionaryTable
 INNER JOIN MaskedIndexTable
    ON (MaskedIndexTable.maskedIndexEncryptedIndex =DictionaryTable.dictionaryEncryptedIndex  )
 WHERE  `dictionaryEncryptedWord` LIKE '...' 


SELECT distinct *
  FROM MaskedIndexTable
 INNER JOIN DictionaryTable 
    ON (MaskedIndexTable.maskedIndexEncryptedIndex = DictionaryTable.dictionaryEncryptedIndex  )
 WHERE   MaskedIndexTable.Id IN  
(
    SELECT DictionaryTable.Id
      FROM  DictionaryTable
     WHERE  `dictionaryEncryptedWord` LIKE '..') 
   AND  `dictionaryEncryptedWord` LIKE '...'

但它们似乎都没有产生正确的结果(我用我的 c# 代码得到的结果)

4

2 回答 2

0

如果您想在 LIKE 条件中使用通配符,则需要更改此设置。

首先在 Access 中创建一个类似于您的第一个查询的查询encryptedWordsQuery

SELECT DictionaryTable.dictionaryEncryptedIndex, DictionaryTable.fileLocation
FROM DictionaryTable
WHERE (((DictionaryTable.dictionaryEncryptedWord) Like "0x0E6E"));

其次在Access中创建一个查询如下:

SELECT MaskedIndexTable.maskedIndex, MaskedIndexTable.maskedIndexEncryptedIndex, MaskedIndexTable.fileLocation
FROM MaskedIndexTable
WHERE Exists (SELECT * 
                FROM encryptedWordsQuery 
               WHERE MaskedIndexTable.maskedIndexEncryptedIndex = encryptedWordsQuery.dictionaryEncryptedIndex
                     AND MaskedIndexTable.fileLocation = encryptedWordsQuery.FileLocation);

我发现创建两个单独的查询比在 Access 中创建一个更容易。

于 2013-04-03T19:22:08.307 回答
0

我认为这应该可行——如果您能够发布示例数据,我们可以制作一个 SQLFiddle 来演示它。

SELECT  dt.dictionaryEncryptedIndex, dt.filelocation 
FROM    DictionaryTable dt
    INNER JOIN MaskedIndexTable mit
        ON mit.fileLocation = dt.fileLocation 
            AND mit.maskedIndexEncryptedIndex = dt.dictionaryEncryptedIndex
WHERE   dt.dictionaryEncryptedWord LIKE '0x0E6E*'
于 2013-04-03T19:24:39.960 回答