最近碰到一个奇怪的sql语句查询问题,简单说A表与B表关联,却没有数据查询出来,求大神帮忙看下
查询出LOW表的sql:
SELECT
t_p_exam_items.item_code,
t_p_exam_items.full_score,
t_p_exam_items.t_p_exam_items_id,
t_e_student_item_score.t_e_student_item_score_id,
AVG(
t_e_student_item_score.score
) AS lowavg
FROM
t_e_student_item_score
INNER JOIN t_p_exam_items ON t_p_exam_items.t_p_exam_items_id = t_e_student_item_score.t_p_exam_items_id
INNER JOIN (
SELECT
a.t_e_student_exam_id
FROM
(
SELECT
@rownum :=@rownum + 1 AS rownum,
t_r_student_score.t_e_student_exam_id,
t_r_student_score.score,
(
SELECT
count(1)
FROM
t_e_student_exam
WHERE
t_e_student_exam.t_p_exam_id = 231
AND t_e_student_exam.absent_mark = 0
) AS cnt
FROM
(
t_r_student_score,
(SELECT @rownum := 0) AS r
)
WHERE
t_r_student_score.t_p_exam_id = 231
ORDER BY
score
) a
WHERE
a.rownum <= a.cnt * 0.27
) low27 ON t_e_student_item_score.t_e_student_exam_id = low27.t_e_student_exam_id
GROUP BY
t_e_student_item_score.t_p_exam_items_id
查询出HIGH表的sql:
SELECT
t_p_exam_items.item_code,
t_p_exam_items.full_score,
t_p_exam_items.t_p_exam_items_id,
t_e_student_item_score.t_e_student_item_score_id,
AVG(
t_e_student_item_score.score
) AS highavg
FROM
t_e_student_item_score
INNER JOIN t_p_exam_items ON t_p_exam_items.t_p_exam_items_id = t_e_student_item_score.t_p_exam_items_id
INNER JOIN (
SELECT
a.t_e_student_exam_id
FROM
(
SELECT
@rownum :=@rownum + 1 AS rownum,
t_r_student_score.t_e_student_exam_id,
t_r_student_score.score,
(
SELECT
count(1)
FROM
t_e_student_exam
WHERE
t_e_student_exam.t_p_exam_id = 231
AND t_e_student_exam.absent_mark = 0
) AS cnt
FROM
(
t_r_student_score,
(SELECT @rownum := 0) AS r
)
WHERE
t_r_student_score.t_p_exam_id = 231
ORDER BY
score DESC
) a
WHERE
a.rownum <= a.cnt * 0.27
) high27 ON t_e_student_item_score.t_e_student_exam_id = high27.t_e_student_exam_id
GROUP BY
t_e_student_item_score.t_p_exam_items_id
WHERE
low.t_p_exam_items_id = high.t_p_exam_items_id
ORDER BY
high.t_p_exam_items_id
LOW表查出来的数据
HIGH表查出来的数据
两段sql用inner join关联,没有任何数据查出,求帮助