1

我对带有一些加密字段的表进行了查询,如下所示:

SELECT groups.`group_id` AS id, `description_s`, 
  AES_DECRYPT(`description_l`, 'decryption_key') AS `description`, 
  AES_DECRYPT(groups.`email`, 'decryption_key') AS email,
  ...
FROM groups
WHERE ...
GROUP BY `id`, `description_s`,`description`,`email`,...
ORDER BY id DESC

这按预期工作,给了我解密的输出。但是,如果我将连接添加到另一个表。

SELECT groups.`group_id` AS id, `description_s`, 
  AES_DECRYPT(`description_l`, 'decryption_key') AS `description`, 
  ...
FROM groups
INNER JOIN details on details.`group_id` = groups.`group_id`
WHERE ...
GROUP BY `id`, `description_s`,`description`,`email`,`customer_name`
ORDER BY id DESC

结果列不再被解密,并且仅当我将 AES_DECRYPT( description_l,dec_key) 而不是别名description放在“group by”子句中时,分组才有效。仍然给我留下加密的列。

我通过使用子查询并在外部进行解密找到了一种解决方法。

SELECT id,description_s, AES_DECRYPT(`description_l`,  'decryption_key') as description
FROM (
   SELECT groups.`group_id` as id, `description_s`, `description_l`
   FROM groups
   INNER JOIN details ON details.`group_id`=groups.`group_id`
   WHERE ... 
   GROUP BY `id`, `description_s`,description_l
) subq
ORDER BY id DESC

我很想知道到底发生了什么。为什么在上面的第二个示例中该列根本没有被解密?有没有办法在不使用子查询的情况下获得分组、解密的结果?

4

0 回答 0