另一个我找不到答案的 MYSQL 问题:
我有这张表,我想获取所有具有 SN>7 且代表次数 > 4 且在第 1-6 列中至少满足 x 次特定条件的 ID。
例如,列 col1-col6 中至少有 3 个单元格的值 > 1。
第一部分很简单(SELECT * FROM table WHERE SN > 7 AND reps > 4....
),但我无法弄清楚第二部分。
谢谢!
ID SN reps col1 col2 col3 col4 col5 col6
A 12 3 0.6 1 3 -2 1 3
B 6 5 3.2 1.1 -3.3 3 0 0
C 300 6 1.3 -0.4 0 0.6 -0.5 -3.3
最佳答案
尝试:
SELECT * FROM table
WHERE SN > 7 AND reps > 4 and
(case when `1` > 1 then 1 else 0 end +
case when `2` > 1 then 1 else 0 end +
case when `3` > 1 then 1 else 0 end +
case when `4` > 1 then 1 else 0 end +
case when `5` > 1 then 1 else 0 end +
case when `6` > 1 then 1 else 0 end) >= 3
关于当至少满足 x 列中的条件时,MYSQL 选择行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16223166/