2016-07-25 54 views
1

我想在SQL Server中對相同的yAxisTitle進行分組,下圖顯示了我的數據。如何使用SQL Server對行值進行分組?

enter image description here

預期結果:

enter image description here

查詢我所用:

select 
    q.questionId, q.questionName, 
    p.perspectiveTitle, x.xAxisTitle, y.yAxisTitle, c.value 
from 
    coaching_questionPerspectiveMap as c 
inner join 
    Coaching_question as q on c.questionId = q.questionId 
inner join 
    Coaching_perspective as p on c.perspectiveId = p.perspectiveId 
inner join 
    coaching_xAxisData x on c.xAxisDataId = x.xAxisDataId 
inner join 
    coaching_yAxisData y on c.yAxisDataId = y.yAxisDataId 
where 
    q.questionId = 14 
    and p.perspectiveId = 1 
order by 
    c.sort 

請提供任何解決辦法嗎?

感謝,

+0

發表您的問題一點點清晰.. –

+0

在您預期的結果你沒有對這些數據進行分組,您剛剛通過yAxisTitle訂購了它。這是你想要的嗎? – Simon

+0

是的,我無法對行進行分組。 –

回答

0

如果你只是想訂購的數據,以便它顯示了在yAxisTitle組,使用:

select 
    q.questionId, q.questionName, 
    p.perspectiveTitle, x.xAxisTitle, y.yAxisTitle, c.value 
from 
    coaching_questionPerspectiveMap as c 
inner join 
    Coaching_question as q on c.questionId = q.questionId 
inner join 
    Coaching_perspective as p on c.perspectiveId = p.perspectiveId 
inner join 
    coaching_xAxisData x on c.xAxisDataId = x.xAxisDataId 
inner join 
    coaching_yAxisData y on c.yAxisDataId = y.yAxisDataId 
where 
    q.questionId = 14 
    and p.perspectiveId = 1 
order by 
    y.yAxisTitle, c.sort 
相關問題