题目链接:点击打开链接
题目大意:略。
解题思路:解决方案(1) 高级思路;一开始以为题目是这个意思,最后一个最合适的进电梯的人选(见补充代码)
AC 代码
--解决方案(1) SELECTa.person_nameFROMQueuea, QueuebWHEREa.turn>=b.turnGROUPBYa.person_idHAVINGSUM(b.weight) <=1000ORDERBYa.turnDESCLIMIT1--解决方案(2) SELECTperson_nameFROM ( SELECT :=+weightper_sum, person_nameFROMQueue, (SELECT :=0) initORDERBYturn) RSWHEREper_sum<=1000ORDERBYper_sumDESCLIMIT1
补充代码
SELECTRS.itemperson_nameFROM ( SELECT :=falseflag, :=+IF(+weight<=1000, IF( :=true, weight, 0), 0) per_sum, :=IF( , person_name, ) itemFROMQueue, (SELECT :=0, :=null, :=false) initORDERBYturn) RSORDERBYRS.per_sumDESCLIMIT1