sql查询结果本身要被使用两次
时间:2021-07-01 10:21:17
帮助过:6人阅读
b
as(
SELECT (
SELECT D .CONTENT_HTML
FROM MIC_PAPER_PROBLEMS D
WHERE D .tm_id
= pm.tm_id ) questionTitle,
( SELECT P .ANSWER_HTML
FROM MIC_PAPER_PROBLEMS P
WHERE P .TM_ID
= pm.tm_id ) rightAns,
pm. ID pushId,
PM.tm_id questionId,
PM.USER_ANSWER yourAnswer
FROM MIC_TD_EXERCISE_PUSH_PROBLEM pm, MIC_TD_EXERCISE_USER_PUSH ph
WHERE pm.push_id
= ph. ID
AND ph.
USER_ID = ?
AND ph.SUBJECT_ID
= ?
and PM.IS_CORRECT
= 2
order by PH.PUSH_TIME,PM.CREATE_TIME
)
select rownum seq, b.
*
from b
where b.pushId
in (
select min(b.pushId)
from b
group by b.QUESTIONID)
这样在oracle将as中的内容查询出来之后,命名为b,然后执行最下面的select查询,其中where条件中的无关子查询是为了保证用户对同一道题的错题只显示一个(比如,题目a,用户答了两次,都答错了,题目表中会记录两条数据,此处只将该题目展示一次即可)。
sql查询结果本身要被使用两次
标签: