What if I don't have a column I can use as an

2019-07-09 20:32发布

问题:

As seen here: http://www.tsqltutorials.com/pivot.php

What if I don't have a column I can perform a SUM upon? How do I get a pivot'ed table result?

回答1:

There's always COUNT(0), another option is to create a common table expression and create an extra column on top of your query with the appropriate value and then use that for the PIVOT.



回答2:

Could you not just add a column with an alias and then refer to the alias, style:

select bar, baz, 0 as foo from tabletable

Would that work?



标签: sql pivot