1

I have two tables in below format:

Table 1:

R.no       name      type
--------------------------
1.          Apple    1
2.          Apple    2
3           Apple.   3
4.          Apple.   1
5           apple.   2

Table 2:

R.no     type.     S. Name
-------------------------------
1.         1.       Fresh
2.         2.       Bbbb
3.         3.       Cccc

My required output is

R. No.  Name.    Fresh.    Bbbb.     Cccc
-------------------------------------------
1.      Apple.   2.        2.        1

can anyone help on this?

2
  • 1
    Please explain the logic behind your output. Commented Sep 6, 2019 at 7:19
  • I believe it suppose to be simple count of types and pivot the result Commented Sep 6, 2019 at 7:43

1 Answer 1

1

You may try this.

with cte as 
(
  select A.id, A.value, b.type, b.sname from A inner join B on A.code=B.type
)
 select value,
       sum(case when sname='Fresh' then 1 else 0 end) Fresh,
       sum(case when sname='Bbbb' then 1 else 0 end) Bbbb,
       sum(case when sname='Cccc' then 1 else 0 end) Cccc
from cte
group by value

Working fiddle for same is Fiddle.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.