Need a query

Database
Enthusiast

Need a query

Hi Experts,

 Write a query for this ?

custid      productname      qty

-------     ------------    ----

c100     prodcabc         3

c100     prodcabc         4

c100         prodcabc      5

oupt:

---

custid     product-QTY1     PRODUCT-QTY2       PRODUCT-QTY3

----------  ---------               --------------              ------------

C100L      3                                  4                         5

3 REPLIES
Enthusiast

Re: Need a query

Hi Harish,

I hope you looking for this.

sel

custID

,coalesce((case when productname='prodcabc' then  qty end),'' ) as product-QTY1

,coalesce((case when productname='xxx' then  qty end),'' ) as product-QTY2

from table

group by 1

Enthusiast

Re: Need a query

Hi Ena,

In this query you are not grouping all the non-aggregate values. So it fails. Please check.

Enthusiast

Re: Need a query

Thanks for replay..

I tried to this query 

sel

custID

,coalesce((case when productname='prodcabc' then  qty end),'' ) as product-QTY1

,coalesce((case when productname='xxx' then  qty end),'' ) as product-QTY2

from table

group by 1,2,3.

But...

The query not get correct answer..

Thanks,

Harish