2012-05-14 62 views
0

我的查询通过jira问题(专门针对jira的组件)提取错误项列表,我需要找出如何在此查询中输入多个pkey,单个pkey可以正常工作,然而当我声明多个pkey时,它会抛出一条错误消息。在mysql中为单个变量声明多个变量

在以下查询中,abc-123是一个jira bug id,子查询查找组件名称,第二个子查询将获取项目名称,其余查询将拉出与组件相关的错误列表,我想输入'def-456 ”, 'JDK-985' 旁边的 'ABC-123',我试图设置新的变量但是它没有工作,能有人帮

$

set @pkey := 'abc-123'; 

select jiraissue.*, co.* 
from jiraissue,project,issuetype,nodeassociation,component, 
customfieldvalue cv 
,customfieldoption co 
where 
component.cname = (SELECT component.cname 
FROM nodeassociation, component, jiraissue 
WHERE component.ID = nodeassociation.SINK_NODE_ID 
AND jiraissue.id = nodeassociation.SOURCE_NODE_ID 
AND nodeassociation.ASSOCIATION_TYPE = 'IssueComponent' 
AND pkey = @pkey) and 
project.pkey = (SELECT substring_index(jiraissue.pkey,'-',1) as project_name 
FROM nodeassociation, component, jiraissue 
WHERE component.ID = nodeassociation.SINK_NODE_ID 
AND jiraissue.id = nodeassociation.SOURCE_NODE_ID 
AND nodeassociation.ASSOCIATION_TYPE = 'IssueComponent' 
AND pkey = @pkey) and 
issuetype.pname = 'Bug' and 
jiraissue.project = project.id and 
jiraissue.issuetype = issuetype.id and 
nodeassociation.association_type = 'IssueComponent' and 
nodeassociation.source_node_entity = 'Issue' and 
nodeassociation.source_node_id = jiraissue.id and 
nodeassociation.sink_node_entity = 'Component' and 
nodeassociation.sink_node_id = component.id 
and jiraissue.id = cv.issue 
and cv.stringvalue = co.id 
and cv.customfield = 10020; 

回答

1

尝试更换

AND pkey = @pkey 

本:

AND pkey in (@pkey, @pkey1, @pkey2) 

,然后在顶部:

set @pkey := 'abc-123', @pkey1 := 'def-456', @pkey2 = 'ghi-789'