Let's look at this task.
Determine the number of models of each type of product for each maker from table Product.
I hope that the comments to the code clear enough to write a PIVOT operator without cribs. Let’s try it.
Calculate the average price on laptops depending on screen size.
Task is elementary and solved by the grouping:
Unlike pivot tables, in PIVOT operator, explicit list of columns is required to output. This is a serious restriction, because need to know what kind of data, and therefore we can apply this operator, as a rule, only to lookup tables (or rather, to the data taken from lookup tables).
If the examples studied seem insufficiently to understand and use without difficulties this operator, I will come back to it when I will think up nontrivial examples where PIVOT operator usage allows simplifying a code essentially.
I wrote this opus to help those who having trouble with PIVOT operator. I can agree that in relational language SQL(Structured Query Language) is a database computer language designed for the retrieval and management of data in relational database management systems (RDBMS), database schema creation and modification, and database object access control management.SQL it looks a foreign matter. Indeed, otherwise it cannot be due to rotation (transposition) of the table is not a relational operation, but operation with multidimensional data structures.
|Создание интернет магазина на Битрикс|
|Закажите интернет магазин под ключ сейчас! Антикризисные цены! Звоните|
|Купить гироскутер в спб|
|Гироскутер купить! Официальный имортер. Гарантия! Ремонт|
|Деревообрабатывающие станки. Инструментов и расходных материалов|