Home > database >  Beginners turn bosses, A column in the SQL is different, B are the same. If more than 5 A column cor
Beginners turn bosses, A column in the SQL is different, B are the same. If more than 5 A column cor

Time:09-23

Are table LS_1, only AB two columns, tens of thousands of data, want A different column, column B have the same, if more than 5 A column corresponding to the same column B in C as 1,

A B C
1 a, 1
2 a 1
3 c 0
4 b 0
5 a 1
6 a 1
7 c 0
8 a 1
. . .

CodePudding user response:

SELECT A, B, (SELECT the IF (COUNT (0) & gt;=5, 0) FROM LS_1 WHERE TT TT. B=T.B) C FROM LS_1 T;

CodePudding user response:

If slow, add index to B,
  • Related