SQL Rows to Columns

后端 未结 2 1429
Happy的楠姐
Happy的楠姐 2020-11-30 12:17

I have a table and want to transpose its rows to columns, similar to a pivot table but without summarising.

For example I have the following tables:

         


        
2条回答
  •  旧时难觅i
    2020-11-30 12:43

    Do your grouping and aggregating first, using Quassnoi's answer as an intermediate result.

    Crosstabulation should only be done when you are no longer going to be doing set oriented operatons on the results. Some SQL dialects have keywords like PIVOT, TRANSFORM or CROSSTABULATE to accomplish this, but you're probably better off using XSLT.

提交回复
热议问题