I am trying to process some data, stored in an Oracle DB, for a machine learning model I am working on.
My current query uses this line in the SELECT statement to identify records that have a field that occurs elsewhere in the database:
CASE SIGN(COUNT(*) - 2) WHEN -1 then 0 else 1 END AS "REPEAT_OFFENDER_BIT"
So basically it says "if there are multiple records with this field (which is determined by my GROUP BY clause), put a one in the REPEAT_OFFENDER_BIT column, else put a zero.
I also need to make sure that the timestamps associated with these records it finds as having a certain common field are not the same. Only then would the record get a one rather than a zero.
Let's say my table columns are these:
fname | lname | ssn | chargeddate
A row should get a one for REPEAT_OFFENDER_BIT only if there exists another record with the same SSN and a different charged date.
What are my options for achieving this? My SQL is quite primitive so I came here for help. Thank you!
Best Answer
Sample data:
The query: