TheJoeIaut
TheJoeIaut

Reputation: 1532

Pivot - How would i do this?

I have following Table:

╔═══════════╦═══════════╦════════════╦═══════╗
║ productid ║ IsProcess ║ IsCosmetic ║ Yield ║
╠═══════════╬═══════════╬════════════╬═══════╣
║         1 ║         1 ║          0 ║ 0,99  ║
║         1 ║         0 ║          1 ║ 0,98  ║
║         2 ║         1 ║          0 ║ 0,85  ║
║         2 ║         0 ║          1 ║ 0,9   ║
╚═══════════╩═══════════╩════════════╩═══════╝

And I need to create this:

╔════════════╦═══════════════╦════════════════╗
║ product id ║ Process Yield ║ Cosmetic Yield ║
╠════════════╬═══════════════╬════════════════╣
║          1 ║ 0,99          ║ 0,98           ║
║          2 ║ 0,85          ║ 0,9            ║
╚════════════╩═══════════════╩════════════════╝

How would I do such thing?

Upvotes: 0

Views: 46

Answers (1)

user359040
user359040

Reputation:

Try:

select productid,
       sum(IsProcess * Yield) ProcessYield,
       sum(IsCosmetic * Yield) CosmeticYield
from myTable
group by productid

Upvotes: 1

Related Questions