Есть таблицы к примеру:
[dbo].[Applications] [dbo].[Deals]
| ID | DealID | status | | ID | DealState |
+----+--------+----------+ +------+-----------+
| 1 | 3362 | Approved | | 3362 | Signed |
| 2 | 4578 | Draft | | 4578 | Signed |
| 3 | 1145 | Approved | | 1145 | Void |
| 4 | 2245 | Approved | | 2245 | Signed |
| 5 | 3331 | Approved | | 3331 | Void |
Запрос:
select
Count(a.ID) as [Utver],
Count(d.ID) as [Zakl]
from
[Applications] a
inner join Deals d ON a.DealID = d.ID
where
a.[Status] = 'Approved' and d.DealState in ('Signed')
Результат:
| Utver | Zakl |
+-------+------+
| 3 | 3 |
Запрос не правильно работает(кол-во записей со статусом 'Approved' = 4)
Как выбрать записи чтобы результат был:
| Utver | Zakl |
+-------+------+
| 4 | 2 |