I am working with SQL Server 2012.
I want to get the count of column as well as the rows with specific condition in each group.
The query I have in mind looks something like this:
select count(column1), (column2 where column2 contains 'page1')
group by column1
I know that the above query isn't correct but I want to show the idea.
Sample data
column1 column2 ------- -------- x1 'temp/page1_l' x1 'temp/page2_f' x2 'temp/page2_d' x2 'temp/page1_k' x2 'temp/page2_e'
Expected output
count(column1) column2 -------------- -------------- 2 'temp/page1_l' 3 'temp/page1_k'
How can I achieve that output?
page1_l
andpage1_k
)? In this simple example (only five rows), it is easy to see that they are the only ones withpage1
in the string. But what ifx1
hadpage1_l
andpage1_m
?