编辑:
抱歉,查询不可读,我在截止日期前。我设法通过将此查询分成两个较小的查询并在 Java 中执行一些业务逻辑来解决问题。还是想知道为什么这个查询可以随机时间返回两个不同的结果。
因此,它会随机返回一次所有预期结果,其他时间只返回一半。我注意到,当我编写它时加入每个连接,并在每次连接后执行,最后它会返回所有预期的结果。因此,如果存在某种 MySql 内存或其他限制,它不会在连接中占用整个表,那么我会徘徊。还阅读不确定的查询,但不知道该说什么。
请帮助,询问是否需要澄清,并提前感谢您。
RESET QUERY CACHE;
SET SQL_BIG_SELECTS=1;
set @displayvideoaction_id = 2302;
set @ticSessionId = 3851;
select richtext.id,richtextcross.name,richtextcross.updates_demo_field,richtext.content from
(
select listitemcross.id,name,updates_demo_field,listitem.text_id from
(
select id,name, updates_demo_field, items_id from
(
SELECT id, name, answertype_id, updates_demo_field,
@student:=CASE WHEN @class <> updates_demo_field THEN 0 ELSE @student+1 END AS rn,
@class:=updates_demo_field AS clset FROM
(SELECT @student:= -1) s,
(SELECT @class:= '-1') c,
(
select id, name, answertype_id, updates_demo_field from
(
select manytomany.questions_id from
(
select questiongroup_id from
(
select questiongroup_id from `ticnotes`.`scriptaction` where ticsession_id=@ticSessionId and questiongroup_id is not null
) scriptaction
inner join
(
select * from `ticnotes`.`questiongroup`
) questiongroup on scriptaction.questiongroup_id=questiongroup.id
) scriptgroup
inner join
(
select * from `ticnotes`.`questiongroup_question`
) manytomany on scriptgroup.questiongroup_id=manytomany.questiongroup_id
) questionrelation
inner join
(
select * from `ticnotes`.`question`
) questiontable on questionrelation.questions_id=questiontable.id
where updates_demo_field = 'DEMO1' or updates_demo_field = 'DEMO2'
order by updates_demo_field, id desc
) t
having rn=0
) firstrowofgroup
inner join
(
select * from `ticnotes`.`multipleoptionstype_listitem`
) selectlistanswers on firstrowofgroup.answertype_id=selectlistanswers.multipleoptionstype_id
) listitemcross
inner join
(
select * from `ticnotes`.`listitem`
) listitem on listitemcross.items_id=listitem.id
) richtextcross
inner join
(
select * from `ticnotes`.`richtext`
) richtext on richtextcross.text_id=richtext.id;