我的查询无效,请帮我查找错误

时间:2021-01-25 09:30:25

标签: mysql mariadb

这是我的查询

SELECT SUBQUERY.user_id AS user_id,

SUBQUERY.username, GROUP_CONCAT(SUBQUERY.role

ORDER BY SUBQUERY.role SEPARATOR ', ') AS roles,

SUBQUERY.firstname,

SUBQUERY.lastname,

SUBQUERY.email,

SUBQUERY.create_time AS 'user creation date',

IF((

SELECT a.action

FROM auditlog a

WHERE a.action = 'Account: DELETE' AND substr(SUBQUERY.username, INSTR(a.user,"(") + 1, INSTR(a.user,")") - INSTR(SUBQUERY.username,"(") - 1) = SUBQUERY.user_id


)IS NOT NULL, "deactivated", IF(SUBQUERY.locked_time IS NULL, "active", "inactive")) AS "status",
lastLogin

-- ,

-- (

-- SELECT MAX(a.time)

-- FROM auditlog a

-- WHERE a.action = 'LOGIN SUCCESSFUL' AND substr(SUBQUERY.username, INSTR(a.user,"(") + 1,
 
INSTR(a.user,")") - INSTR(SUBQUERY.username,"(") - 1) = SUBQUERY.user_id

-- ) AS last_login

FROM

(

SELECT u.id AS user_id,

u.username,

role,

u.firstname,

u.lastname,

u.email,

u.create_time,

u.locked_time

FROM USER u

INNER JOIN

user_has_role uhr ON

u.id = uhr.user_id

INNER JOIN

role r ON

r.id = uhr.role_id

ORDER BY 2

)SUBQUERY

INNER JOIN



(SELECT

max(a.TIME) AS LastLogin,

CAST(SUBSTR(a.user, INSTR(a.user,"(")+1, INSTR(a.user,")") -1- (INSTR(a.user,"("))) AS INT) AS user_id
FROM auditlog a

WHERE a.action = 'LOGIN SUCCESSFUL'

GROUP BY user_id) b

ON b.user_id = SUBQUERY.user_id

GROUP BY SUBQUERY.user_id

ORDER BY SUBQUERY.user_id

1 个答案:

答案 0 :(得分:0)

INSTR(SUBQUERY.username,"(") - 1) 括号不配对