2

我有具有 MySQL 数据库后端的 FreeRADIUS。用户存储在 radcheck 表中:

radcheck 表图像

我想从中选择所有具有用户名、速度配置文件和密码的用户(在不久的将来会有更多用户)。所以我会得到结果 lukasfazik, testovacieheslo, OPTIK100。我试过这个:

SELECT  username, password, profile
FROM (SELECT t1.username, t1.value AS password, t2.value AS profile
      FROM radcheck AS t1, radcheck AS t2
      WHERE t1.value != t2.value
     ) AS arrgh;

我从中得到了这个:

我的查询图像的结果

GROUP BY 不起作用,我收到一个错误:

[42000][1055] SELECT 列表的表达式 #2 不在 GROUP BY 子句中,并且包含在功能上不依赖于 GROUP BY 子句中的列的非聚合列“arrgh.password”;这与 sql_mode=only_full_group_by 不兼容

4

2 回答 2

0

好像你想旋转你的桌子。在这种情况下,最简单的方法是将表连接到自身。对于更复杂的情况,您可以查看本指南

select a.*, b.password 
from (username, value profile from FreeRADIUS where attribute = 'user-profile') a
join (username, value password from FreeRADIUS where attribute = 'cleartext-password') b 
on a.username = b.username
于 2020-05-08T10:53:04.817 回答
0

您可以使用子查询选择所需的属性并加入它们:

> SELECT * FROM
    (SELECT username, value as profile FROM radcheck WHERE attribute = "User-Profile") as t1
NATURAL JOIN
    (SELECT username, value as pass FROM radcheck WHERE attribute = "Cleartext-Password") as t2
;

+------------+----------+-----------------+
| username   | profile  | pass            |
+------------+----------+-----------------+
| lukasfazik | OPTIK100 | testovacieheslo |
+------------+----------+-----------------+

子查询将包含用户名和主表中所选属性的值。

> SELECT username, value as profile FROM radcheck WHERE attribute = "User-Profile"

+------------+-----------+
| _username_ | _profile_ |
+------------+-----------+
| lukasfazik | OPTIK100  |
+------------+-----------+
| testuser   | OPTIK200  |
+------------+-----------+
| fooUser    | OPTIK500  |
+------------+-----------+
| ...        | ...       |
+------------+-----------+

通过嵌套自然连接,可以类似地添加更多属性。

于 2020-05-21T15:38:27.343 回答