यहाँ एक उदाहरण है: इनपुट:

company    amount     vendor    ID(ai)
  A1        100         B1        1
  A2        150         B1        2
  A3        200         B2        3
  A1        100         B3        4

आउटपुट:

vendor   A1      A2      A3     Total
  B1     100     150     NULL   250
  B2     NULL    NULL    200    200
  B3     100     NULL    NULL   100
1
Taohao Wang 24 सितंबर 2018, 18:55

1 उत्तर

सबसे बढ़िया उत्तर

ऐसा लगता है कि आप सशर्त एकत्रीकरण चाहते हैं:

select vendor,
       sum(case when company = 'A1' then amount end) as a1,
       sum(case when company = 'A2' then amount end) as a2,
       sum(case when company = 'A3' then amount end) as a3,
       sum(amount) as total
from t
group by vendor;
0
Gordon Linoff 24 सितंबर 2018, 18:58