我的整个查询有点复杂,所以我将尝试显示您需要了解我的问题,我正在从数据库中获取票证,它显示标题、创建者、负责票证的人,以及最后一个更新者,对于创建者和负责人,我找到他们ID
的tickets_users.users_id
类型和类型 1 或 2,这取决于他们是票的创建者还是负责人,标题和票本身的所有信息表现在为用户命名tickets
,他们的 ID,他们的名字等等users
所以我的查询看起来像这样:
SELECT
tickets.id,
tickets.name,
GROUP_CONCAT(
CASE WHEN tickets_users.type = 1 THEN
CONCAT(users.firstname, ' ', users.realname)
END) AS creator,
GROUP_CONCAT(
CASE WHEN tickets_users.type = 1 THEN
CONCAT(tickets_users.users_id)
END) AS creator_id,
GROUP_CONCAT(
CASE WHEN tickets_users.type = 2 THEN
CONCAT(users.firstname, ' ', users.realname)
END) AS in_charge,
GROUP_CONCAT(
CASE WHEN tickets_users.type = 2 THEN
CONCAT(tickets_users.users_id)
END) AS in_charge_id,
tickets.date,
tickets.priority,
tickets.date_mod,
tickets.status,
tickets.users_id_lastupdater,
MAX(CASE WHEN tickets.users_id_lastupdater = users.id
THEN CONCAT(users.firstname, ' ', users.realname)
END) AS last_updater,
tickets.content
FROM
tickets
JOIN tickets_users ON tickets_users.tickets_id = tickets.id
JOIN users ON users.id = tickets_users.users_id
WHERE tickets.id = ?");
我的问题是JOIN users ON users.id = tickets_users.users_id
它适用于负责人和创建者,但如果不是负责人回复或修改票证,他将不会出现在“最后修改者”中,因为last_updater
ID
它在表格中tickets
。我尝试加入,JOIN users ON (users.id = tickets_users.users_id AND , glpi_tickets.users_id_lastupdater)
但没有成功。有任何想法吗?