这是我从表中获得排名的代码,但我想用INNER JOIN连接另外两个表,但是当我使用INNER JOIN时Rank会改变..请帮我解决这个问题...
SELECT ex_studentid, ex_studentname, ex_subjid, ex_batchno, ex_examdate,
ex_code, ex_marks, @curRank := @curRank + 1 AS rank
FROM cp_exams p, (SELECT @curRank := 0) r ORDER BY ex_marks DESC;
INNER JOIN代码
SELECT ex_studentid, ex_studentname, ex_subjid, ex_batchno, ex_examdate, ex_code,
ex_marks, @curRank := @curRank + 1 AS rank
FROM cp_exams p INNER JOIN `cp_students`
ON stu_studentID = ex_studentid, (SELECT @curRank := 0) r ORDER BY ex_marks DESC;
-------------------我的Mysql表-----------------
CREATE TABLE `cp_exams` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`ex_studentid` INT(11) NOT NULL,
`ex_studentname` VARCHAR(255) NULL DEFAULT NULL,
`ex_subjid` INT(11) NULL DEFAULT NULL,
`ex_batchno` VARCHAR(255) NULL DEFAULT NULL,
`ex_examdate` DATE NULL DEFAULT NULL,
`ex_code` INT(20) NULL DEFAULT NULL,
`ex_marks` INT(11) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=MyISAM
AUTO_INCREMENT=29
我想用cp_exams连接这些表,并获得ex_marks的学生排名.....
CREATE TABLE `cp_students` (
`stu_ID` INT(11) NOT NULL AUTO_INCREMENT,
`stu_studentID` INT(11) UNSIGNED NOT NULL,
`stu_regdate` DATE NOT NULL,
`stu_studentname` VARCHAR(255) NOT NULL,
`stu_address` VARCHAR(255) NULL DEFAULT NULL,
`stu_sex` VARCHAR(45) NOT NULL,
`stu_bday` DATE NULL DEFAULT NULL,
`stu_con_home` VARCHAR(255) NULL DEFAULT NULL,
`stu_con_mobile1` VARCHAR(255) NULL DEFAULT NULL,
`stu_con_mobile2` VARCHAR(255) NULL DEFAULT NULL,
`stu_email` VARCHAR(255) NULL DEFAULT NULL,
`stu_notes` VARCHAR(255) NULL DEFAULT NULL COLLATE 'big5_chinese_ci',
`stu_passGrade` VARCHAR(45) NULL DEFAULT NULL,
`stu_image_name` VARCHAR(255) NULL DEFAULT NULL,
`stu_nic` VARCHAR(45) NULL DEFAULT NULL,
`stu_school` VARCHAR(255) NULL DEFAULT NULL,
`stu_accesskey` INT(11) NULL DEFAULT NULL,
PRIMARY KEY (`stu_ID`)
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM
AUTO_INCREMENT=800
;
CREATE TABLE `cp_exams_list` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`ex_code` INT(20) NULL DEFAULT NULL,
`ex_des` VARCHAR(255) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM
AUTO_INCREMENT=4
;