Hi guys.
I have a table in sql server like this:
Insurance_DateOfDefinition Insurance_FreeCardNo Insurance_UsedStatus
1398/05/01 1000001 True
1398/05/01 1000002 True
1398/05/01 1000003 False
1398/05/01 1000004 False
1398/05/01 1000005 False
1398/05/01 1000006 False
1398/05/01 1000007 True
1398/05/01 1000008 False
1398/05/01 1000009 False
1398/05/01 1000010 True
1398/06/01 1000011 True
1398/06/01 1000012 True
1398/06/01 1000013 True
1398/06/01 1000014 False
1398/06/01 1000015 False
1398/06/01 1000016 False
1398/06/01 1000017 False
1398/06/01 1000018 False
For Insurance_UsedStatus, 1 means the card number is USED and 0 Means it's free.
I need a query to give me the following result:
Insurance_DateOfDefinition NoOfRegisteredCards_InThisDate NoOfFreeCards_InThisDate
1398/05/01 10 6
1398/06/01 8 5
I tried the command below:
SELECT
Insurance_DateOfDefinition
,COUNT (Insurance_FreeCardNo) NoOfRegisteredCards_InThisDate
, (select COUNT (Insurance_FreeCardNo) FROM InsuranceFreeCardNo where Insurance_UsedStatus=1) NoOfFreeCards_InThisDate
FROM InsuranceFreeCardNo
group by Insurance_DateOfDefinition
The result was:
Insurance_DateOfDefinition NoOfRegisteredCards_InThisDate NoOfFreeCards_InThisDate
1398/05/01 10 7
1398/06/01 8 7
As you see, the column NoOfFreeCards_InThisDategive takes the wrong values.
Would you please help me with this problem?
Thank you in advance.
Rara.