有一张表
CREATE TABLE geography_schedule
(
id
int(10)UNSIGNED NOT NULL,
geography_address_id
int(10)UNSIGNED NOT NULL,
geography_city_id
int(10)UNSIGNED NOT NULL,
sort
int(5)UNSIGNED NOT NULL DEFAULT'500',
site
varchar(5)NOT NULL DEFAULT'site',
group_id
int(10)NOT NULL DEFAULT'0',
day
int(10)NOT NULL DEFAULT'1',
all_day
tinyint(2)NOT NULL DEFAULT'0',
freeday
int(10)NOT NULL DEFAULT'0',
from
varchar(5)NOT NULL DEFAULT '09:00',
to
varchar(5)NOT NULL DEFAULT '18:00',
timestamp
时间戳NOT NULL DEFAULT CURRENT_TIMESTAMP,
timestamp_update
时间戳NOT NULL DEFAULT CURRENT_TIMESTAMP
)ENGINE = InnoDB DEFAULT CHARSET = utf8;
INSERT INTO geography_schedule
(from
,to
,geography_address_id
,day_from
,day_to
,group_id
)价值观
('09:00','18:00',533,1,1,1),
('09:00','18:00',533,2,2,1),
('11:00','17:00',533,3,3,1),
('11:00','17:00',533,4,4,1),
('09:00','18:00',533,5,5,1),
('10:00','17:00',533,6,6,1),
('09:00','18:00',533,7,7,1;)
我在这个表enter image description here
中有一个mysql查询SELECT `from`,`to`, `geography_address_id`, MIN(`day`) as `day_from`
,MAX(`day`) as `day_to`,`group_id`
FROM `geography_schedule`
WHERE `geography_address_id` = 533
GROUP BY `from`,`to`
ORDER BY `geography_schedule`.`day` ASC
结果:
我需要按行分组9:00 - 18:00以节省日期day_from
& day_to
按正确顺序排列。
是否可以以这样的方式使用GROUP BY,它会给出这样的结果?