在mysql中为单个变量声明多个变量

时间:2012-05-14 03:48:57

标签: mysql sql

我的查询通过jira问题提取错误项目列表(特定于jira的组件),我需要找出如何在此查询中输入多个pkey,单个pkey工作正常,但是当我声明多个pkey时它会抛出错误信息。

在下面的查询中,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 个答案:

答案 0 :(得分:1)

尝试替换

AND pkey = @pkey

用这个:

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

然后在顶部:

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