Now want to achieve:
If the first column of a line or two values are the same, and the third column of a line or two values are y, will the two lines, one line in the third column values instead of n, several other don't change, is below the results;
How do leaders use SQL implementation? Thank you very much!
CodePudding user response:
CREATE TABLE # a (name VARCHAR (20), grade class VARCHAR (20), whether out of a VARCHAR (10))
INSERT INTO # a
SELECT 'wang', '0101', 'y' UNION ALL
SELECT 'xiao li', '0101', 'n' UNION ALL
SELECT 'zhang', '0101', 'n' UNION ALL
SELECT 'wang', '0201', 'y' UNION ALL
SELECT 'xiao li', '0201', 'n' UNION ALL
SELECT 'zhang', '0201', 'y'
The UPDATE
T1
Whether the SET t1. [out]='n'
The FROM (SELECT row_number () OVER (ORDER BY [name]) n * FROM # a) t1,
(SELECT row_number () OVER (ORDER BY [name]) n * FROM # a) t2
WHERE a t1. [name]=t2. [name] AND t1. Whether [out of]='y' AND t2. Whether [out of]='y'
AND t1. N & gt; T2. N
CodePudding user response:
The manual way upstairs, automatically add a loopCodePudding user response: