我有以下MySQL表Test_Results
| ID | Test_ID | Device_OS| Status | Date | Device_ID |
| 1 | 1 | Android | passed | 2015/10 | 1 |
| 2 | 1 | Android | failed | 2015/10 | 1 |
| 3 | 15 | iOS | failed | 2015/11 | 2 |
| 4 | 20 | Android | passed | 2015/11 | 1 |
| 5 | 27 | Android | failed | 2015/11 | 1 |
| 6 | 10 | iOS | failed | 2015/12 | 2 |
| 7 | 5 | Android | passed | 2015/12 | 1 |
我需要在ID = 1的设备上选择失败的测试,但是在ID = 2的设备上传递。
所以我需要根据Device_ID比较值,请你指点一下在互联网上搜索的内容。
答案 0 :(得分:2)
如果您希望满足这两个条件,请尝试以下方法:
SELECT Test_ID
FROM Test_Results
WHERE Test_ID IN (SELECT Test_ID FROM Test_Results WHERE Device_ID = 1 AND Status LIKE 'failed')
AND Device_ID = 2 AND Status LIKE 'passed'
答案 1 :(得分:0)
select Test_ID, COUNT(Test_ID) as TEST_COUNT from Test_Results
where (Status='failed' AND Device_ID = 1) OR (Status='passed' AND Device_ID = 2)
group by Test_ID
Having TEST_COUNT>1
答案 2 :(得分:-1)
以安全的方式制作....
SELECT *
FROM Test_Results
WHERE (`Device_ID` = 1 AND `Status` = 'passed')
OR
(`Device_ID` = 2 AND `Status` = 'failed');
希望能完美地运作......