一个关于查询连续2次为负数的 SQL语句
1个回答

select t9.name, t9.`成绩` as `最后一批成绩`,t8.`成绩` as `上一批成绩` from (select t3.*, t5.`成绩` from (select a3.name,max(`date`) as date2 from atest as a3 where `成绩` <0 anda3.date not in (SELECT max( date ) AS date FROM atestWHERE `成绩` <0 GROUP BY `name`) GROUP BY `name`) as t3 left joinatest as t5 on t5.date = t3.date2) as t8, (select t1.name, t1.date,t1.`成绩` from (SELECT `id`,`name` , `date` , `成绩` FROM atest WHERE `成绩` <0) as t1,(SELECT max( date ) AS date FROM atest WHERE `成绩` <0 GROUP BY `name`) as t2 where t1.date = t2.date) as t9 where t8.name = t9.name