Time:09-19
CodePudding user response:
filling what are the rules?
-If not object_id (N 'Tempdb for.. # T ') is null Drop table # T Go The Create table # T (int [name], [id] nvarchar (23), [mobile] nvarchar (23)) Insert # T Select 1, N 'empty', N '123' union all Select 2, N '888', N 'empty' union all Select 1, N '777', N 'empty' union all Select 2, N 'empty', N '00' Go - the end of the test data SELECT DISTINCT * FROM (SELECT A. name, CASE WHEN a. id='empty' THEN b. ELSE a. id card and id card end AS ='empty' cell phone CASE WHEN a. THEN b. mobile phones ELSE a. end AS mobile phone The FROM # T a LEFT the JOIN # T b ON b. name=a. name AND b. phone & lt;> A. cell phone AND b. id & lt;> A. id ) t
written in MSSQL, similar to mysql The test data -If not object_id (N 'Tempdb for.. # T ') is null Drop table # T Go The Create table # T (int [name], [id] nvarchar (23), [mobile] nvarchar (23)) Insert # T Select 1, N 'empty', N '123' union all Select 2, N '888', N 'empty' union all Select 1, N '777', N 'empty' union all Select 2, N 'empty', N '00' Go - the end of the test data SELECT DISTINCT * FROM (SELECT A. name, CASE WHEN a. id='empty' THEN b. ELSE a. id card and id card end AS ='empty' cell phone CASE WHEN a. THEN b. mobile phones ELSE a. end AS mobile phone The FROM # T a LEFT the JOIN # T b ON b. name=a. name AND b. phone & lt;> A. cell phone AND b. id & lt;> A. id ) t
Page link:https//www.codepudding.com/database/13376.html