There is a table inside with the employee's social security record of social security, had a staffId field associated with employee table, and table a deleteFlag field 0 of social security is not deleted, 1 is deleted, if the employee didn't sign the social security is not exist the staffId social security records,
Now I want to write a SQL, is found to staff to record all did not sign a contract, if employees have social security but deleted at the beginning, there is only a record, and deleteFlag of 1 is also needs to be found out,
The SQL what to write, the great god,
CodePudding user response:
Is not did not sign a contract, is not sign of social securityCodePudding user response:
SELECT
*
The FROM
Employee table
WHERE
NOT the EXISTS (SELECT 1 FROM social security table WHERE the staff table. StaffId=social security table. StaffId AND social security table. DeleteFlag=0)
CodePudding user response:
Found to all employees, employee ID is not yet buy social security staff ID in it:Select * from employee table where staffid not in (select staffid from social security table where deleteFlag='0');
CodePudding user response:
Reference