0

これが元のクエリです:、2つの列名(ラベル、カウント)を持つo / pを生成します:

label      count 
Fails      1
Pass       3

上記のデータを生成する私が書いたクエリは次のとおりです

select r.pname as resolution
,lb.label
,count(r.pname) as occurences
from issuelink
inner join jiraissue p on issuelink.source = p.id
inner join jiraissue c on issuelink.destination = c.id
inner join issuelinktype t on issuelink.linktype = t.id
inner join resolution r on c.resolution = r.id
inner join issuestatus istat on p.issuestatus = istat.sequence
inner join label lb on c.id = lb.issue
where t.linkname = 'jira_subtask_link'
and p.pkey in (@pkey)
and c.issuetype in ('13')
and r.pname not in ('Fails Smoke Test - General Failure', 'Fails Smoke Test - New Firmware Available')
and label in ('SmokeTest', 'fullcert', 'bfv', 'papercert')
group by r.pname;

あなたの提案に従って、私はクロス関数を使用しようとしましたが、「構文を確認してください」というエラーがスローされます。

select  100.0 * fail.cnt / (fail.cnt + pass.cnt) as c
from    (
        select  r.pname as label
        ,       count(r.pname) as cnt
        from issuelink
        inner join jiraissue p on issuelink.source = p.id
        inner join jiraissue c on issuelink.destination = c.id
        inner join issuelinktype t on issuelink.linktype = t.id
        inner join resolution r on c.resolution = r.id
        inner join issuestatus istat on p.issuestatus = istat.sequence
        inner join label lb on c.id = lb.issue
        where t.linkname = 'jira_subtask_link'
        and p.pkey in ('SRPDTVTPV-3')
        and c.issuetype in ('13')
        and r.pname not in ('Fails Smoke Test - General Failure', 'Fails Smoke Test - New Firmware Available')
        and label in ('SmokeTest', 'fullcert', 'bfv', 'papercert')
        group by r.pname
        ) as fail
cross join    
        (
        select  r.pname as label
        ,       count(r.pname) as cnt
        from issuelink
        inner join jiraissue p on issuelink.source = p.id
        inner join jiraissue c on issuelink.destination = c.id
        inner join issuelinktype t on issuelink.linktype = t.id
        inner join resolution r on c.resolution = r.id
        inner join issuestatus istat on p.issuestatus = istat.sequence
        inner join label lb on c.id = lb.issue
        where t.linkname = 'jira_subtask_link'
        and p.pkey in ('SRPDTVTPV-3')
        and c.issuetype in ('13')
        and r.pname not in ('Fails Smoke Test - General Failure', 'Fails Smoke Test - New Firmware Available')
        and label in ('SmokeTest', 'fullcert', 'bfv', 'papercert')

        group by r.pname
        ) as pass
where   fail.label = 'Fails Certification'
        and pass.label = 'Passes Certification'
4

1 に答える 1

2

を使用する 1 つの方法を次に示しcross joinます。

select  100.0 * a.count / (a.count + b.count) as c
from    YourQuery a
cross join    
        YourQuery b
where   a.label = 'a'
        and b.label = 'b'

集計を使用した別のアプローチを次に示します。もう少しトリッキーですが、YourQuery を使用するのは 1 回だけです。

select  100.0 * cnt_a / (cnt_a + cnt_b) as c
from    (
        select  max(case when label = 'a' then count end) as cnt_a
        ,       max(case when label = 'b' then count end) as cnt_b
        from    YourQuery
        ) as SubQueryAlias
于 2012-06-29T00:32:50.667 に答える