【问题标题】:My Query Isn't Working, Please Help Me Finding The Error我的查询不起作用,请帮我找出错误
【发布时间】:2021-01-25 09:30:25
【问题描述】:

这是我的查询,伙计们,我有一个错误,无法运行我的查询:

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

【问题讨论】:

标签: mysql mariadb


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-03
    • 2021-07-18
    • 2011-10-22
    • 2021-09-19
    • 2021-08-31
    • 2017-01-25
    • 2012-11-22
    • 1970-01-01
    相关资源
    最近更新 更多