Sql 中如何以两个动态的列为条件来判断第三列的结果,例如
U1 OPERATION toolid location TOOL_ALLOWED PRODUCT
1 940000 764 68 TRUE 18A*
2 940000 763 68 TRUE 18A*
3 940000 762 68 FALSE 18A*
4 940000 761 68 TRUE 18A*
5 940000 760 68 TRUE 18A*
6 940000 752 68 FALSE 18A*
1 950002 775 68 FALSE 17A*
2 950002 771 68 TRUE 17A*
3 950002 770 68 FALSE 17A*
4 950002 711 68 FALSE 17A*
5 950002 710 68 FALSE 17A*
想要以在相同的operation和product 为条件(例如前六行),来判断是否tool_allowed 小于2个true的结果
不要进行指定 例如case when operation=‘940000’ and product=‘18A*’这样的,因为我的数据很多,不只是这两种,单独写,写不过来
求指点,sql在线急等
没明白 他们之间有什么关联还是什么,如果说都是单独的 也就是前6个判断一次,后6个判断一次的话 那就可以使用分组去重然后作为条件使用
SELECT options,tool_allow,product,count(*) count FROM `product` GROUP BY options,product,tool_allow HAVING tool_allow="TRUE" AND count<2
```