Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.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_Sql_Compare_Mariadb - Fatal编程技术网

比较mysql中相同表的行值

比较mysql中相同表的行值,mysql,sql,compare,mariadb,Mysql,Sql,Compare,Mariadb,我有这样的数据: header_id | class | start_date | end_date ------------------------------------------- 1 | c1 | 20-08-2019 | 22-08-2019 1 | c1 | 22-08-2019 | 24-08-2019 1 | c2 | 24-08-2019 | 27-08-2019 2 | c3 | 25-

我有这样的数据:

header_id | class | start_date | end_date
-------------------------------------------
1         | c1    | 20-08-2019 | 22-08-2019
1         | c1    | 22-08-2019 | 24-08-2019
1         | c2    | 24-08-2019 | 27-08-2019
2         | c3    | 25-08-2019 | 26-08-2019
2         | c3    | 26-08-2019 | 30-08-2019
3         | c1    | 23-08-2019 | 26-08-2019
select header_id. class, min(start_date), max(end_date)
from your_table_name
group by header_id, class
我希望得到以下结果:

header_id | class | start_date | end_date
-------------------------------------------
1         | c1    | 20-08-2019 | 24-08-2019
1         | c2    | 24-08-2019 | 27-08-2019
2         | c3    | 25-08-2019 | 30-08-2019
3         | c1    | 23-08-2019 | 26-08-2019

有没有办法得到这个结果?

根据我的理解,你需要这样的东西:

header_id | class | start_date | end_date
-------------------------------------------
1         | c1    | 20-08-2019 | 22-08-2019
1         | c1    | 22-08-2019 | 24-08-2019
1         | c2    | 24-08-2019 | 27-08-2019
2         | c3    | 25-08-2019 | 26-08-2019
2         | c3    | 26-08-2019 | 30-08-2019
3         | c1    | 23-08-2019 | 26-08-2019
select header_id. class, min(start_date), max(end_date)
from your_table_name
group by header_id, class

您的\u表\u名称
更改为实际名称

根据我的理解,您需要这样的名称:

header_id | class | start_date | end_date
-------------------------------------------
1         | c1    | 20-08-2019 | 22-08-2019
1         | c1    | 22-08-2019 | 24-08-2019
1         | c2    | 24-08-2019 | 27-08-2019
2         | c3    | 25-08-2019 | 26-08-2019
2         | c3    | 26-08-2019 | 30-08-2019
3         | c1    | 23-08-2019 | 26-08-2019
select header_id. class, min(start_date), max(end_date)
from your_table_name
group by header_id, class

您的\u表\u名称
更改为实际名称

使用格式为
2019-12-31
的日期,否则比较、取最小值/最大值等将失败。使用格式为
2019-12-31
的日期,否则比较、取最小值/最大值等将失败。