Hi @Sudip Bhatt ,
Or try:
CREATE TABLE [dbo].[tblTest](
ID INT Identity,
[C_ID] [int] NULL,
[Type] [varchar](max) NULL,
[Title] [varchar](max) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
INSERT INTO [dbo].[tblTest] VALUES(1,'GROUP','Segment'),(1,'GROUP','Loyalty'),
(1,'Lineitem','Revenue'),(1,'Lineitem','EBITDA'),
(2,'Lineitem','Operate'),(2,'Lineitem','Revenue'),
(null,null,null)
select C_ID,sum(case when Type='GROUP' then 1 else 0 end )groupcount,
sum(case when Type='Lineitem' then 1 else 0 end)Lineitemcount
from [dbo].[tblTest]
group by C_ID
Output:
If you have any question, please feel free to let me know.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.