I'm rather vaguely familiar with SQL. I use SQL Server 2012.
I have this table:
|Id | SiteId| SiteDesc |IsNormal| DateReview |FrequencyId|
|3379| 5| colon | 1 | 2016-09-10 00:00:00.000| 1 |
|3381| 5| colon | 0 | 2016-09-15 00:00:00.000| 1 |
|3382| 5| colon | 1 | 2016-09-21 00:00:00.000| 1 |
|3489| 5| colon | 0 | 2016-08-10 00:00:00.000| 1 |
|3851| 5| colon | 1 | 2016-08-16 00:00:00.000| 1 |
|3537| 2| dogon | 1 | 2016-05-05 00:00:00.000| 1 |
|3863| 2| dogon | 1 | 2016-05-20 00:00:00.000| 1 |
IsNormal
column is of BIT
data type.
I need to group the table by SiteId
and DateReview
(only month and year). If in IsNormal
column at least one row has property false, in grouped table it has to be False.
Here is the desired grouped table:
| SiteId| SiteDesc |IsNormal| DateReview |FrequencyId|
| 5| colon | 0 | 2016-09-10 00:00:00.000| 1 |
| 5| colon | 0 | 2016-08-10 00:00:00.000| 1 |
| 2| dogon | 1 | 2016-05-05 00:00:00.000| 1 |