mysql连接查询加密列不解密或分组

时间:2013-06-05 09:26:17

标签: mysql

我在一个表上查询了一些加密字段,如下所示:

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放在'组中时,分组才有效。条款。仍然留给我加密列。

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

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

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

0 个答案:

没有答案