HPQC报表查询生成器

时间:2014-01-15 16:26:48

标签: sql join

我有兴趣解决一个让我疯狂的SQL查询难题。我必须构建一个影响三个表的查询。我试图通过一个过程来解决这个问题,但我想HPQC Report Query Builder无法处理一个过程。所以我必须使用另一种解决方案。

以下是3个步骤的问题:我从第一个表中识别出 bug_id 。使用此ID,我会提供另一个表格以从第二个表格中获取相应的 user_id 。最后一步,我使用第二个表中的user_id查找相应的用户名

SELECT bug_id FROM Bugs WHERE (Color='green') --> RESULT_A
SELECT link_id FROM Link WHERE (the_user = RESULT_A) --> RESULT_B
SELECT username FROM Users WHERE (user_id = RESULT_B)

我试图通过JOINS进行操作,但似乎无法正常工作。因此,我尝试通过仅使用简单的两步(查找)示例来简化问题:

SELECT LINKTABLE.USERID, USERTABLE.USERNAME
FROM  LINKTABLE 
INNER JOIN USERTABLE 
ON LINKTABLE.USERID = USERTABLE.USERID;

HPQC报告:无效声明。

是否有人可以帮我构建简单的查询查询?

更新

这是我对2个表的连接的解决方案:

SELECT
 b.BG_BUG_ID as Defect,
 b.BG_USER_09 as PTR,
 b.BG_STATUS as Status,
 b.BG_SEVERITY as Severity,
 b.BG_USER_01 as Category,
 b.BG_USER_66 as Theme,
 b.BG_USER_64 as Page_Impacted,
 b.BG_DETECTION_DATE as Detected_on_Date,
 b.BG_DETECTION_VERSION as Detected_in_Version,
 l.LN_ENTITY_ID,
 l.LN_ENTITY_TYPE
FROM
 BUG b
JOIN
 LINK l
ON
 b.BG_BUG_ID = l.LN_BUG_ID
WHERE
 (b.BG_BUG_ID = 5555)
AND
 (l.LN_ENTITY_TYPE = 'TEST')
ORDER BY b.BG_BUG_ID ASC

现在我需要添加来自另一个表的第三个信息。所以必须有2个JOINS ..

2 个答案:

答案 0 :(得分:1)

我明白了:

SELECT
 b.BG_BUG_ID as Defect,
 b.BG_USER_09 as PTR,
 b.BG_STATUS as Status,
 b.BG_SEVERITY as Severity,
 b.BG_USER_01 as Category,
 b.BG_USER_66 as Theme,
 b.BG_USER_64 as Page_Impacted,
 b.BG_DETECTION_DATE as Detected_on_Date,
 b.BG_DETECTION_VERSION as Detected_in_Version,
 t.TS_NAME as Testcase
FROM
 BUG b
JOIN LINK l ON b.BG_BUG_ID = l.LN_BUG_ID
JOIN TEST t ON l.LN_ENTITY_ID = t.TS_TEST_ID
WHERE
 (b.BG_BUG_ID = 5555)
AND
 (l.LN_ENTITY_TYPE = 'TEST')
ORDER BY b.BG_BUG_ID ASC

答案 1 :(得分:-2)

select b.bug_id, u.username as Name
from Bugs b
join Link l on b.id = l.the_user
join Users u on l.the_user = u.username
where Color = 'green'