日期:2014-05-17 浏览次数:20528 次
当qq.quesviewtype = 1 时,随机获取24条记录,
当qq.quesviewtype = 2 时,随机获取15条记录,
当qq.quesviewtype = 3 时,随机获取10条记录,
当qq.quesviewtype = 4 时,随机获取18条记录,
以下是一个条件的查询,可以使用union all 进行四个查询的合并,除此外,还是否有更简洁的写法:
select top 24 * from
(select distinct(qq.questionid) questionid,qpv.paperviewid,qq.limitminute,qq.splitscore
,qq.optnum,qq.creator,qq.modifyStatus,qq.parentid,qq.questypeid
,qq.quesviewtype,qq.content,qq.answer,qq.analysis,qq.score,qq.status
,convert(varchar(100),qq.createtime,20) createtime
from qz_question qq with (nolock)
join qz_paper_question qpq with (nolock) on qq.questionid = qpq.questionid
join qz_paper_view qpv with (nolock) on qpq.paperid = qpv.paperid
join qz_point_question qpoq with (nolock) on qq.questionid = qpoq.questionid
join qz_point qpo with (nolock) on qpoq.pointid = qpo.pointid
where qpv.paperviewid = 27714
and ((qq.parentid != 0) or (qq.parentid = 0 and qq.answer is not null))
and qpo.pointlistid = 572
and qq.quesviewtype = 1
) a order by newID()
select * from
(select distinct(qq.questionid) questionid,qpv.paperviewid,qq.limitminute,qq.splitscore
,qq.optnum,qq.creator,qq.modifyStatus,qq.parentid,qq.questypeid
,qq.quesviewtype,qq.content,qq.answer,qq.analysis,qq.score,qq.status
,convert(varchar(100),qq.createtime,20) createtime