Вы можете эмулировать Pivot по диагонали матрицы умножения:
With test ([Id], [Serie], [Month], [Serie number])
As (
Select 1, 'Factura 0003', 'Jan', 4771 Union
Select 2, 'Factura 0003', 'Jan', 4779 Union
Select 3, 'Factura 0003', 'Jan', 4792 Union
Select 4, 'Factura 0003', 'Feb', 4864 Union
Select 5, 'Factura 0003', 'Feb', 4892
), diagonal_matrics ([Month], [Jan], [Feb], [Mar], [Apr], [May], [Jun], [Jul], [Aug], [Sep], [Oct], [Nov], [Dec])
As (
Select 'Jan', 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL Union
Select 'Feb', NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL Union
Select 'Mar', NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL Union
Select 'Apr', NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL Union
Select 'May', NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL Union
Select 'Jun', NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL Union
Select 'Jul', NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL Union
Select 'Aug', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL Union
Select 'Sep', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL Union
Select 'Oct', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL Union
Select 'Nov', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL Union
Select 'Dec', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1
)
Select [Serie],
Min([Serie number] * [Jan]) [Jan Min], Max([Serie number] * [Jan]) [Jan Max],
Min([Serie number] * [Feb]) [Feb Min], Max([Serie number] * [Feb]) [Feb Max],
Min([Serie number] * [Mar]) [Mar Min], Max([Serie number] * [Mar]) [Mar Max],
Min([Serie number] * [Apr]) [Apr Min], Max([Serie number] * [Apr]) [Apr Max],
Min([Serie number] * [May]) [May Min], Max([Serie number] * [May]) [May Max],
Min([Serie number] * [Jun]) [Jun Min], Max([Serie number] * [Jun]) [Jun Max],
Min([Serie number] * [Jul]) [Jul Min], Max([Serie number] * [Jul]) [Jul Max],
Min([Serie number] * [Aug]) [Aug Min], Max([Serie number] * [Aug]) [Aug Max],
Min([Serie number] * [Sep]) [Sep Min], Max([Serie number] * [Sep]) [Sep Max],
Min([Serie number] * [Oct]) [Oct Min], Max([Serie number] * [Oct]) [Oct Max],
Min([Serie number] * [Nov]) [Nov Min], Max([Serie number] * [Nov]) [Nov Max],
Min([Serie number] * [Dec]) [Dec Min], Max([Serie number] * [Dec]) [Dec Max]
From test
Inner Join diagonal_matrics On test.[Month] = diagonal_matrics.[Month]
Group By [Serie]
Пожалуйста, есть изображение, если у вас есть сомнения. –
Используйте выражения CASE. например 'SELECT SERIE, CASE КОГДА x THEN y END [col1] ...' – ZLK
И почему вы не хотите использовать опорную точку? – thepirat000