2011-12-05 63 views
0

enter image description hereSQL複雜查詢與計數

您好我有一個表結構如上述圖像,我需要採取若干列的計數爲一單一列,這些列的諸如

octSecAndthrd1 
octSecAndthrd2 
octSecAndthrd3 
octSecAndthrd4 

計數命名(column1的)一個單個列像明智

最終輸出應爲:

ID | Column1 | Column2

任何想法?

+0

你想要像@chris說的那樣做還是需要一些動態代碼?如果是這樣,列的總數是4的倍數? –

回答

2
select id 
    , sum(octSecAndthrd1 + octSecAndthrd2 + octSecAndthrd3 + octSecAndthrd4) col1 
    , sum(octSecAndthrd5 + octSecAndthrd6 + octSecAndthrd7 + octSecAndthrd8) col2 
    from ...