select a.taskcode from (select taskcode, createdate from tab_task_state_log where taskstate = '4')a,
(select taskcode, createdate from tab_task_state_log where taskstate = '5')b
group by a.taskcode, (b.createdate - a.createdate)* 24 * 60 having (b.createdate - a.createdate)* 24 * 60 < 10
数据量大了就给跪了
你给的sql语句好像有问题的样子?那24 60是个什么鬼?
第二不明白你想要什么结果,所以不知道怎么给你意见。我猜想是你想获取任务由状态4转到状态5消耗的时间吧?
你这条sql语句有子查询,同时对两个子查询结果集做笛卡尔积,这个消耗是很大的。
建议把a表,b表分开来查询,在使用程序处理把,这样一条sql,数据量多的话,数据库会扛不住的。
你和 a 和 b相当于建立了临时表,如果 数据库过多。。内存扛不住