0

在 MySQL 中,我有 2 个表定义如下:

DROP TABLE IF EXISTS `tbl_monitor`;
CREATE TABLE `tbl_monitor` (
 `id` bigint(20) NOT NULL AUTO_INCREMENT,
 `byte_val` int(11) DEFAULT NULL ,
 `int_val` int(11) DEFAULT NULL ,
 `float_val` float DEFAULT NULL ,
 `time` bigint(20) DEFAULT NULL ,
 `variable` bigint(20) DEFAULT NULL ,
 `active` tinyint(1) DEFAULT NULL ,
 `number` varchar(255) DEFAULT NULL,
 `timestamp` varchar(255) DEFAULT NULL,
 PRIMARY KEY (`id`) USING BTREE,
 KEY `FK_cjj1quo5uu1iokxuqxb2aoop3` (`variable`) USING BTREE,
 KEY `time` (`time`) USING BTREE,
 CONSTRAINT `FK_cjj1quo5uu1iokxuqxb2aoop3` FOREIGN KEY (`variable`) REFERENCES `tbl_variable` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;

CREATE TABLE `tbl_variable`  (
 `id` bigint(20) NOT NULL AUTO_INCREMENT,
 `active` tinyint(1) NULL DEFAULT NULL,
 `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' ,
 `number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' ,
 `key_variable` tinyint(1) NULL DEFAULT NULL  ,
 `selected` tinyint(1) NULL DEFAULT NULL  ,
 `board_active` tinyint(1) NULL DEFAULT NULL ,
 `v_type` int(11) NULL DEFAULT NULL ,
 `default_value` int(11) NULL DEFAULT NULL ,
 `data_source` bigint(20) NULL DEFAULT NULL ,
 `variable_group` bigint(20) NULL DEFAULT NULL ,
 `motion` bigint(20) NULL DEFAULT NULL ,
 `alarm_info` bigint(20) NULL DEFAULT NULL ,
 `equipment_maintain_var` bigint(20) NULL DEFAULT NULL,
 `data_src_var_map` bigint(20) NULL DEFAULT NULL ,
 `parameter_set` bigint(20) NULL DEFAULT NULL,
 `lowerlimit` double NOT NULL,
 `toplimit` double NOT NULL ,
 `type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' ,
 `value_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '',
 `interface_text` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' ,
 `monitor_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '',
 `description` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' ,
 `data_source_type` bigint(20) NULL DEFAULT NULL,
 `is_storage` tinyint(1) NULL DEFAULT NULL,
 `curve_range` bigint(20) NULL DEFAULT NULL,
 `lower_of_curves` double NULL DEFAULT NULL,
 `top_of_curves` double NULL DEFAULT NULL,
 `curve_color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
 PRIMARY KEY (`id`) USING BTREE,
 UNIQUE INDEX `UK_bptibcxw3r6djvfvjkfyjysfx`(`data_src_var_map`) USING BTREE,
 INDEX `FK_47dsvuotnfmh56pl7q8t04ans`(`data_source`) USING BTREE,
 INDEX `FK_3a8o9g559hcv7dvp46psxt2h2`(`variable_group`) USING BTREE,
 INDEX `FK_il8dmghmkqssntbrj4bxeh9oo`(`motion`) USING BTREE,
 INDEX `FK_rtj6gs9tv23ye6i6iajlg6che`(`alarm_info`) USING BTREE,
 INDEX `FK_362u3oja2amg203cecn981ihv`(`equipment_maintain_var`) USING BTREE,
 INDEX `FK_k1excwhcxnmu9dp9pk84ddm4o`(`parameter_set`) USING BTREE,
 INDEX `FK_7b2r98qn8ok0f9yfp1bm75uwh`(`data_source_type`) USING BTREE,
 CONSTRAINT `FK_362u3oja2amg203cecn981ihv` FOREIGN KEY (`equipment_maintain_var`) REFERENCES `tbl_equipment_maintain_var` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
 CONSTRAINT `FK_3a8o9g559hcv7dvp46psxt2h2` FOREIGN KEY (`variable_group`) REFERENCES `tbl_variable_group` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
 CONSTRAINT `FK_47dsvuotnfmh56pl7q8t04ans` FOREIGN KEY (`data_source`) REFERENCES `tbl_data_source` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
 CONSTRAINT `FK_7b2r98qn8ok0f9yfp1bm75uwh` FOREIGN KEY (`data_source_type`) REFERENCES `tbl_data_source_type` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
 CONSTRAINT `FK_il8dmghmkqssntbrj4bxeh9oo` FOREIGN KEY (`motion`) REFERENCES `tbl_motion` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
 CONSTRAINT `FK_k1excwhcxnmu9dp9pk84ddm4o` FOREIGN KEY (`parameter_set`) REFERENCES `tbl_parameter_set` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
 CONSTRAINT `FK_rtj6gs9tv23ye6i6iajlg6che` FOREIGN KEY (`alarm_info`) REFERENCES `tbl_alarm_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
 CONSTRAINT `FK_sdkjfsdfshfewdkjfe654d5f4` FOREIGN KEY (`data_src_var_map`) REFERENCES `tbl_data_src_var_map` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 353 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

我下载了 MYSQL 插件,并在 DolphinDB GUI 中执行以下代码:

loadPlugin("C:/MYSQL_V0.96.0/PluginMySQL_win32.txt")

use mysql
connection=connect("127.0.0.1", 3306, `newuser, `dolphindb123, `ecimp_ver3)

t1=load(connection,"tbl_variable");
db1=database("C:/dolphindb_gj/tblVariable");
saveTable(db1, t1, `tbl_variable);

login('admin', "123456")
TIME_RANGE = 2017.12.10 +  0..(365*30)
db2=database("dfs://tblMonitor", RANGE, TIME_RANGE)

schema=select name,type from extractSchema(connection,`tbl_monitor)
update schema set type="TIMESTAMP" where name="time"

tbl_monitor=loadEx(connection,db2,"tbl_monitor","time","tbl_monitor",schema)

成功完成后,我想把下面的mysql查询代码翻译成dolphindb代码:

select m.*,v.monitor_type from  m, v 
where m.time between 1515570908112 and 1515657308112  and m.variable=v.id and v.selected=1 
ORDER BY m.time

所以我写代码如下:

db1=database("C:/dolphindb_gj/tblVariable");
db2=database("dfs://tblMonitor", RANGE, TIME_RANGE)
v=loadTable(db1,`tbl_variable);
m=loadTable(db2,"tbl_monitor"); 

select  m.*, v.monitor_type from ej(m,v,`variable,`id)
where m.time between 2018.01.10T07:55:08.112:2018.01.11T07:55:08.112 and v.selected=1 
order by  m.time

然后我在 DolphinDB GUI 中执行,错误发生如下:

2019-07-01T16:18:45.346: execution was completed with exception
All columns of a table must have the same length.

如何解决?

4

1 回答 1

0

选择 m.*, monitor_type from ej(m,v, variable,id) 其中 m.time 在 2018.01.10T07:55:08.112:2018.01.11T07:55:08.112 和 v.selected=1 之间按 m.time 排序

于 2019-07-31T01:38:19.903 回答