0

给定ticket具有主键id的表ticket_custom和具有复合键的表,ticket,name我如何加入id = ticket and name=X and id = ticket and name=Y.

该表ticket_custom允许扩展工单表,它具有字段ticket,name,value

我可以做一个单一的加入:

SELECT id, summary, owner, ticket_custom.value
FROM ticket
INNER JOIN ticket_custom
ON id=ticket_custom.ticket AND ticket_custom.name='X'

我需要类似的东西:

SELECT id, summary, owner, ticket_custom.value, ticket_custom.value
FROM ticket
INNER JOIN ticket_custom
ON id=ticket_custom.ticket AND ticket_custom.name='X' AND ticket_custom.name='Y'

其中第一个ticket_custom.value是 for 的值,id,x第二个是 for的值id,y

4

3 回答 3

4

如果我理解正确,这就是您要查找的内容:

SELECT id, summary, owner, c1.value, c2.value
FROM ticket t
INNER JOIN ticket_custom c1  ON t.id = c1.ticket AND c1.name = 'X'
INNER JOIN ticket_custom c2  ON t.id = c2.ticket AND c2.name = 'Y'
于 2012-12-06T15:21:37.133 回答
0

我这应该可以解决问题:

SELECT id, summary, owner, ticket_custom.value, ticket_custom.value
FROM ticket
INNER JOIN ticket_custom
ON ticket.id=ticket_custom.ticket
WHERE (ticket_custom.name='X' OR ticket_custom.name='Y')
于 2012-12-06T15:20:58.650 回答
0

也许

SELECT id, summary, owner, ticket_custom.value, ticket_custom.value
FROM ticket
INNER JOIN ticket_custom
ON id=ticket_custom.ticket AND ticket_custom.name='X' 
    OR id=ticket_custom.ticket AND ticket_custom.name='Y'
于 2012-12-06T15:23:28.920 回答