I have a table Messages in SQL Server 2012.
There are three columns in table
ID which is an identity column,
MessageID (int) which is a foreign key to other table and
IsRead field which is a bit not null column.
At a given point of time table can contain huge number of records with IsRead column value either 1 or 0.
I want to write a single query in which I find count of read and unread messages in two separate columns.
I am trying to use new windows function introduced in SQL Server 2012 for efficiency.
How can I do it ?
Please check whether this helps.
Or you can select in two columns like: