mysql添加为成绩表添加名次

对于一种这样的表,为score添加名次 <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC8AAACbCAIAAAB9HlWYAAADqklEQVR4nO3czW7TQBAA4HkeekSWgl8hDxGph5X6FhzAlbjEr1BObU65YFQSTpxA5NTevDcECKVES3+S0joOh43j9axtqqjrcdQZzaVVIn3adZqZ3VFhZYSU8ttiRZVSSmANax5Pcx4+B//lufWeoYBO+Olpa6rStWZxe6czSZZSyo+/V3V5IsAL39a/Ztus1nwN90Acrl8XdcEIp5r54q/OCk3UBeierN9w2GtWM75Ixxfp+Et/D0RwkY6PBXj9I/1L+8dHzYJmuWyB5mZ+qzNZLqWUo2k6mqajz/1nIF5P09H0XRege5yOpuloGh94AF7/SL/msfMhmnR0LLIH+MXBK+FWc32z0Kmfmw+zJVVKKeHqeq5zrfmxpMoSzemvhCqllHB5daMzSRIp5en3hCqllPDn8lrnfZJIKd//vKfK9mlkmwLQd/qKLpRSrGENa7aJSACAiOg1cegD+EL4FRpUmTrW5KZyDQC0S7MBtUJj1snEGlS1E2tQnfykNHHom110waSUAlS1O9bUhVIKUNVOrEFVO7WmWLUTa1CdzBpDg6p2RRr4FJJqYVZ6bcyfWZMHa6qDNca3OCoqmtdEwg/jnFXwKKXwyb5jjRlx6G9o9JpI2GuDTvabtBRWhlATiZLWt6DR9wxUlLUGnew7lsShjzeIThOJQscA1mcK3TO41dSGUgqf7LPG0KB7BmINOtlnjaFpdc8wowvWsIY1W8Wgt/4C7w2oNZPAWyMGPexRdpXuWGPEoAdeMGmJxsLMlF2lO1dMAq/0qaHRZDHoQclOoZ6hMY29V8qu0t0C8o/UbBJ4JWvTqCZ/bCr+3qCewbWmJpRdpbPG0KCegViDqnTWGJpW9wwPbX4cBGuqgzXVwRodeirIPi+m0MSh7/vW4agiOdnX9wvlZ+lNa7K7jjac7OfXQPQa80rqPxr39wx4+Abd36nG7xnyKF+bdmn4nmFXNHzPsCsa7hnKgzXVwZrqePKawrRA8UucRlM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aEV8pdycD4vEKD2+A91qCr17yNsyCeTlFmODWXY5iZpCUhzPQMsXeEikScAe38Ug52cxyGd2vae3DRAkW+ksS5iMh9F4+cSZBNTk/3RIeLWUdv0tk6ARJNnlJAoma3mnpff0tcGCRLRi92Rcg9WYL/dxIJoLkiaFIFr2J50YcSy3+KNhPJCP8vWenjaYkEh7NAkM7fhQmF8mgbSDQzOTAIAkk86dq0tVZXDoczS0Wbu9FHr3ULT1ODSdZRFfnqhLX2U5YPxCzHtzQdKkWopf6/Jd/ZQItJMk3cQBV0Nh3gVJk0IQUOJbORlv6elpQzHOUJvvAyTnQ3Uxpvf0uKEYZ6jNuyBpUi2F4uu9oY4DCvMuSJoUgqD4em+o44DCPEGCvqGOAwrzLkioWgqJxGWFJCORSJoIEhKpRgQJiVQjgoREqhFBQiLViCAhkWpEkJBINSJISKQa/R9TgnqRWEVF6QAAAABJRU5ErkJggg==" alt=""> 对于mysql来说 名次用临时变量来保存,考虑对于相同的分数名次一样,可以先将表按分数分组,与名次单独查询出来 select @counter:=@counter+1 as rank,t.score from (select…