MySQL Query get ranking method (absolutely valid)

Source: Internet
Author: User
Tags mysql query

http://blog.csdn.net/k8080880/article/details/11253305

Select

Case if Pid=0 Then
When the case is @prevType =quetype_id then @rank: [Email protected]+1
When @prevType: =quetype_id then @rank: =1 End
else Que_sort end as Que_sort2,

A.*

From
SELECT
0 exam_id,
Q.pid,

Q.que_sort,

@prevType: =q.quetype_id

From
T_home_question rel LEFT Join
T_question Q on (rel.question_id=q.question_id or Rel.question_id=q.pid)
WHERE rel.home_id=320 ORDER BY Quetype_id,pid
) A, (SELECT @rank: =0, @prevType: =null) B

MySQL Query get ranking method (absolutely valid)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.