I have a table with multiple columns where I need to check if the column ANI (ANI is the mobile numbers) called for their first time or they have existing record on the previous dates, I need to return like 1 if exist and 0 if not
I have tried a query but seems to be far away, any guidance will be much appreciated
SELECT DISTINCT(ANI) as mobile
FROM ODCalls
(CallLocalTime) >= '2022-06-08 00:00:00'
and ANI NOT IN (
select ANI
from ODCalls
WHERE (CallLocalTime) >= '2022-06-01 00:00:00'
and (CallLocalTime) >= '2022-06-07 23:59:59'
)
CodePudding user response:
SELECT T.ANI AS MOBILE
FROM ODCalls AS T
GROUP BY T.ANI
HAVING MIN(CAST(T.CallLocalTime AS DATE)=CAST(GETDATE()AS DATE)
You can try something like this. I am not completely sure with out sample data about possible issues with datetime. This query should detect mobile phones, which have made the first call today.