A
A
Andrey Vinogradov2018-03-19 23:12:07
SQL Server
Andrey Vinogradov, 2018-03-19 23:12:07

MS SQL select is it possible to create such a query?

There is a database on MS SQL Server:

Microphone		Platform	Quantity

Sm58			Pivka		0
Sm91			Pivka		1
Akg414			Pivka		1
E904			Pivka 		5
Sm58			Intercon	0
Sm91			Intercon	1
Akg414			Intercon	1
E904			Intercon 	1

Is it possible to create a query to get a result like this:
Microphone	Pivka	Intercon

Sm58		0	0
Sm91		1	1
Akg414		1	1
E904		5	1

I do not quite understand where to dig, there is not enough knowledge ((((

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mynigoo, 2018-03-21
@fire_on_line

select Microphone
  ,sum(case Platform when 'Pivka' then  Quantity else 0 end)
  ,sum(case Platform when 'Intercon' then  Quantity else 0 end)
from MyTable
group by Microphone

K
Konstantin Tsvetkov, 2018-03-19
@tsklab

Using PIVOT statements .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question