Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 为什么同一查询会得到不同的输出?_Mysql - Fatal编程技术网

Mysql 为什么同一查询会得到不同的输出?

Mysql 为什么同一查询会得到不同的输出?,mysql,Mysql,我一直试图回答这个问题: 我想出了一个对我来说很好的解决方案,但我不能在菲德尔身上复制。现在我想知道为什么会这样 数据: 基本上,问题是如何创建列group\u id,如下面的屏幕截图所示。group\u id的思想是查看所有共享id相同值的子组,只要两行之间没有重叠时间,即当前行的开始时间>比最后一行的结束时间增加1 我的查询给出了上述输出,在我的机器(MySQL workbench)上似乎运行良好: 但是,在fidel上,我无法复制它(所有值均为1): 这是因为我的工作台版本吗?MySQ

我一直试图回答这个问题:

我想出了一个对我来说很好的解决方案,但我不能在菲德尔身上复制。现在我想知道为什么会这样

数据:

基本上,问题是如何创建列
group\u id
,如下面的屏幕截图所示。
group\u id
的思想是查看所有共享
id
相同值的子组,只要两行之间没有重叠时间,即当前行的开始时间>比最后一行的结束时间增加1

我的查询给出了上述输出,在我的机器(MySQL workbench)上似乎运行良好:

但是,在fidel上,我无法复制它(所有值均为1):


这是因为我的工作台版本吗?

MySQL不保证在
select
子句中计算顺序表达式。因此,您无法保证赋值
@id:=id
是在其他表达式之前还是之后计算的。那么在子组中进行任何排序的最佳实践是什么?升级到MySQL 8.0并使用。好的,我会检查一下。非常感谢。
create table your_table (id int(11), start_time time, end_time time);
insert into your_table (id, start_time, end_time) values (102, '11:01:00', '11:30:00');
insert into your_table (id, start_time, end_time) values (101, '10:00:00', '10:20:00');
insert into your_table (id, start_time, end_time) values (100, '10:00:00', '12:00:00');
insert into your_table (id, start_time, end_time) values (100, '10:15:00', '12:30:00');
insert into your_table (id, start_time, end_time) values (100, '12:15:00', '12:45:00');
insert into your_table (id, start_time, end_time) values (100, '13:00:00', '14:00:00');
insert into your_table (id, start_time, end_time) values (101, '09:00:00', '13:00:00');
insert into your_table (id, start_time, end_time) values (101, '09:30:00', '13:30:00');
insert into your_table (id, start_time, end_time) values (105, '10:30:01', '11:00:00');
insert into your_table (id, start_time, end_time) values (105, '10:00:00', '10:20:00');
insert into your_table (id, start_time, end_time) values (105, '10:21:00', '10:30:00');
insert into your_table (id, start_time, end_time) values (105, '14:30:01', '15:00:00');
insert into your_table (id, start_time, end_time) values (106, '10:00:00', '10:22:00');
insert into your_table (id, start_time, end_time) values (107, '10:19:00', '10:20:00');
insert into your_table (id, start_time, end_time) values (108, '10:01:00', '10:16:00');
select 
    id, start_time, end_time,
    case when @id = id and start_time >= @end_time then @reminder + 1 else 1 end as group_id,
    @id:=id as id_set,
    @reminder:= case when @id = id and start_time >= @end_time then @reminder + 1 else 1 end as reminder,
    @end_time:=end_time
from your_table t,
(select @id_check = 1) a,
(select @reminder = 1) b,
(select @end_time = '00:00:00') c
order by id, start_time;