我怎么能把那些colum转换成行?

时间:2018-03-20 01:42:08

标签: sql sql-server tsql pivot unpivot

enter image description here

转换后

应该是

public String countTable(){
    List<WebElement> located_elements = driver.findElements(By.xpath("//*[@class='z-listbox-body']/table/tbody[2]/tr"));
    int count = 0;
    for(WebElement located_element:located_elements){
        count ++;
    }
    String s = String.valueOf(count);

    return s;
}

如果你能提供帮助,我将非常感激。

1 个答案:

答案 0 :(得分:2)

您需要APPLY(即CROSS APPLY)才能将转换为

select 
       qtynames as Month,
       max(case when dt = '01' then qty end) [01],
       max(case when dt = '02' then qty end) [02], 
       max(case when dt = '03' then qty end) [03],...
from table t cross apply (
    values ('month', dt, 'planqty', planqty), ('month', dt, 'actqty', actqty)
)a(mnames, dates, qtynames, qty)
group by qtynames