0

I'm having difficulties creating the result i want on a specific situation.

I have a two tables:

1: sales by warehouse:

+-------------+---------------+--------------+

warehouse | type -------- | value

+-------------+---------------+--------------+

A--------------XX-------------234234----------

A-------------- YY------------ 234343--------------

A-------------- ZZ------------ 534534--------------

B-------------- XX------------ 234432--------------

B-------------- YY------------ 767563--------------

B-------------- ZZ------------ 312332--------------

c-------------- XX------------ 234234--------------

....

2: users by warehouse:

user--------|---warehouse

john--------|-- A

john--------|-- B

john--------|-- C

peter-------|-- A

Daniel------|-- C

Kim---------|-- B

Kim---------|-- C

....

So i created this query:

select a.warehouse, type, value from sales_by_warehouse A left join users_warehouse B ON A.warehouse=B.warehouse where b.user = 'user_logged_on_software'

This works perfectly by giving me the warehouse that the user has access to and its values but, now, i wanted to invert the result such as in a pivot table so that if the user was Peter, this would be the result:

type--|-----A----

XX----|-----123123

YY----|-----3423423

ZZ----|-----3423345

And if the user was kim:

type--|-----B---------|-----C

XX----|-----123123-|---234324

YY----|-----423423-|---245435

ZZ----|-----423345-|---456233

Is there a way to do this with only select statements, without views or PS?

Cœur
  • 37,241
  • 25
  • 195
  • 267
valter.vx
  • 137
  • 4
  • 11

0 Answers0