开发者

select mysql data using MAX

I have a testdata like this:

DROP TABLE SELECT_PASS;
CREATE TABLE SELECT_PASS(ID INT(20),TESTCASE VARCHAR(20),RESULT VARCHAR(20));
INSERT INTO SELECT_PASS VALUES(1,"TC1","PASS");
INSERT INTO SELECT_PASS VALUES(2,"TC2","PASS");
INSERT INTO SELECT_PASS VALUES(3,"TC3","INCONC");
INSERT INTO SELECT_PASS VALUES(4,"TC1","FAIL");
INSERT INTO SELECT_PASS VALUES(5,"TC21","FAIL");
INSERT INTO SE开发者_Python百科LECT_PASS VALUES(6,"TC4","PASS");
INSERT INTO SELECT_PASS VALUES(7,"TC3","PASS");
INSERT INTO SELECT_PASS VALUES(8,"TC2","PASS");
INSERT INTO SELECT_PASS VALUES(9,"TC1","TIMEOUT");


SELECT TESTCASE, MAX(RESULT) FROM SELECT_PASS  GROUP BY TESTCASE;

The resultset I get is :

TC1 TIMEOUT
TC2 PASS
TC21    FAIL
TC3 PASS
TC4 PASS

Basically I want to see those testcases which never passed.

Any way to do it?

Thanks.


This will give you all the test case names that don't have any pass results:

SELECT DISTINCT TESTCASE FROM SELECT_PASS
 WHERE TESTCASE NOT IN (SELECT TESTCASE FROM SELECT_PASS WHERE RESULT = 'PASS')


SELECT 
  TESTCASE, 
  MAX(RESULT) RESULT
FROM 
  SELECT_PASS  
GROUP BY 
  TESTCASE
HAVING 
  TESTCASE != 'PASS'


I'd use numeric values for result, with pass being the greatest (or lowest), and the MAX query:

SELECT TESTCASE, MAX(RESULT) AS r FROM SELECT_PASS  GROUP BY TESTCASE HAVING r < 999

where 999 is the numeric value for PASS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜