我有 2 张桌子,ticket 和 ticket_custom。
以下是表格的设置方式。
我有一个 Web 界面,我可以在其中更改状态(表 ticket_custom 中的值) Web 界面添加一个新条目,而不是更新原始条目。
ticket name value
1 state Ready for Final Verification
2 state Ready for Final Verification
1 state Verified
最后一行被添加
所以我需要修改查询。
SELECT p.value AS __color__,
id AS ticket, summary, component, version, c.value AS state, milestone, t.type AS type,
owner, status,
time AS created,
changetime AS _changetime, description AS _description,
reporter AS _reporter
FROM ticket t, ticket_custom c
LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority' AND id = c.ticket
WHERE status <> 'closed' AND id = c.ticket
ORDER BY CAST(p.value AS int), milestone, t.type, time, c.ticket
该查询现在返回两个条目。我试图在 where 子句中添加一个嵌套选择。
SELECT g.ticket
FROM ticket_custom g
WHERE g.ticket = id
ORDER BY g.ticket DESC LIMIT 1
所以 -
SELECT p.value AS __color__,
id AS ticket, summary, component, version, c.value AS state, milestone, t.type AS type,
owner, status,
time AS created,
changetime AS _changetime, description AS _description,
reporter AS _reporter
FROM ticket t, ticket_custom c
LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority' AND id = c.ticket
WHERE status <> 'closed' AND id = c.ticket and (
SELECT g.ticket
FROM ticket_custom g
WHERE g.ticket = id
ORDER BY g.ticket DESC LIMIT 1 )
ORDER BY CAST(p.value AS int), milestone, t.type, time, c.ticket
显然我做错了什么。