Springboot我希望查询begin_time和entry_time两个字段包含的所有时间

小刘
  • 526

有一张表 bulldozer_overview,我希望查询begin_time和entry_time包含的所有时间

表的结构

-- ----------------------------
-- Table structure for bulldozer_overview
-- ----------------------------
DROP TABLE IF EXISTS `bulldozer_overview`;
CREATE TABLE `bulldozer_overview` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '车辆ID',
  `license_number` varchar(50) NOT NULL COMMENT '车牌号',
  `data_source` int(2) DEFAULT '0' COMMENT '数据来源',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `begin_time` varchar(50) DEFAULT NULL COMMENT '出发时间',
  `end_time` varchar(50) DEFAULT NULL COMMENT '到达时间',
  `elimination` varchar(50) DEFAULT NULL COMMENT '消纳地点',
  `rubbish_type` varchar(50) DEFAULT NULL COMMENT '垃圾类型',
  `order_number` varchar(100) DEFAULT NULL COMMENT '运单编号',
  `site_name` varchar(50) DEFAULT NULL COMMENT '工地名称',
  `site_area` varchar(20) DEFAULT NULL COMMENT '工地所属区',
  `elimination_area` varchar(20) DEFAULT NULL COMMENT '消纳地点所属区',
  `transport_name` varchar(50) DEFAULT NULL COMMENT '运输企业',
  `transport_area` varchar(20) DEFAULT NULL COMMENT '运输企业所属区',
  `transport_volume` float(10,2) DEFAULT NULL COMMENT '运输量(吨)',
  `driving_status` int(11) DEFAULT '2' COMMENT '车辆行驶状态',
  `entry_time` timestamp NULL DEFAULT NULL COMMENT '进消纳厂时间',
  `flag_delete` int(2) DEFAULT '0' COMMENT '删除标识',
  `driving_type` int(2) DEFAULT '0' COMMENT '行驶状态',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=62 DEFAULT CHARSET=utf8 COMMENT='渣土车出入总览表';

-- ----------------------------
-- Records of bulldozer_overview
-- ----------------------------
BEGIN;
INSERT INTO `bulldozer_overview` VALUES (0, '京Q89HX3', 0, '2021-04-08 16:48:36', '2021-06-03 16:33:25', '2021-03-20 10:59:10', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 2, NULL, 0, 0);
INSERT INTO `bulldozer_overview` VALUES (1, '京MBE065', 0, '2021-04-08 16:48:36', '2021-06-03 16:33:29', '2021-03-21 10:59:10', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 2, NULL, 0, 0);
INSERT INTO `bulldozer_overview` VALUES (2, '京MFV786', 0, '2021-04-08 16:49:37', '2021-06-03 16:33:34', '2021-03-22 10:59:42', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 2, NULL, 0, 0);
INSERT INTO `bulldozer_overview` VALUES (3, '京CAB975', 0, '2021-04-08 16:49:37', '2021-06-03 16:30:15', '2021-03-24 10:59:10', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 2, NULL, 0, 0);
INSERT INTO `bulldozer_overview` VALUES (4, '京LAA101', 0, '2021-04-08 16:49:37', '2021-06-03 16:30:17', '2021-03-24 10:49:29', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 2, NULL, 0, 0);
INSERT INTO `bulldozer_overview` VALUES (5, '京LAA101', 0, '2021-06-03 16:30:30', '2021-06-03 16:30:37', '2021-03-24 10:49:29', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 2, NULL, 0, 0);
INSERT INTO `bulldozer_overview` VALUES (6, '京LAA101', 0, '2021-06-03 16:32:04', '2021-06-03 16:32:16', '2021-03-24 10:49:29', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 2, NULL, 0, 0);
INSERT INTO `bulldozer_overview` VALUES (59, '京LAA101', 0, '2021-06-03 16:32:55', '2021-06-03 16:33:12', '2021-03-24 10:49:29', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 2, NULL, 0, 0);
INSERT INTO `bulldozer_overview` VALUES (60, '京LAA101', 0, '2021-06-03 16:33:02', '2021-06-03 16:33:47', '2021-05-30 10:49:29', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 2, NULL, 0, 0);
INSERT INTO `bulldozer_overview` VALUES (61, '京LAA101', 0, '2021-06-03 16:34:12', '2021-06-03 16:34:37', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 2, '2021-05-30 10:49:29', 0, 1);
COMMIT;

SET FOREIGN_KEY_CHECKS = 1;

我的答案

select 
case 
    when driving_type = 0 then date_format(begin_time, '%Y年%m月%d日')
    when driving_type = 1 then date_format(entry_time, '%Y年%m月%d日') end 日期
from bulldozer_overview
group by 
case 
    when driving_type = 0 then date_format(begin_time, '%Y年%m月%d日')
    when driving_type = 1 then date_format(entry_time, '%Y年%m月%d日') end
回复
阅读 469
1 个回答
✓ 已被采纳
select 
case 
    when driving_type = 0 then date_format(begin_time, '%Y年%m月%d日')
    when driving_type = 1 then date_format(entry_time, '%Y年%m月%d日') end 日期
from bulldozer_overview
group by 
case 
    when driving_type = 0 then date_format(begin_time, '%Y年%m月%d日')
    when driving_type = 1 then date_format(entry_time, '%Y年%m月%d日') end
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
你知道吗?

宣传栏