表的结构如下:
basic表
id int primary_key auto_increment
rawId int foreign_key
productId int foreign_keyraw表
rawId int primary_key auto_increment
raw1 float
...
raw1000 floatproduct表
productId int primary_key auto_increment
product1 float
...
product500 float现有两个数据文件(路径为pathRaw, pathProduct),其中关于raw的结构为:(50行*1000列,Tab分隔)
20.1 20.2 32.1 ... 20.1
...
42.1 20.1 42.5 ... 23.1
关于product的结构和关于raw的类似
现要把两个数据文件的数据导入到数据表中,并要求保持三张表的主外键关系,请教各位~
basic表
id int primary_key auto_increment
rawId int foreign_key
productId int foreign_keyraw表
rawId int primary_key auto_increment
raw1 float
...
raw1000 floatproduct表
productId int primary_key auto_increment
product1 float
...
product500 float现有两个数据文件(路径为pathRaw, pathProduct),其中关于raw的结构为:(50行*1000列,Tab分隔)
20.1 20.2 32.1 ... 20.1
...
42.1 20.1 42.5 ... 23.1
关于product的结构和关于raw的类似
现要把两个数据文件的数据导入到数据表中,并要求保持三张表的主外键关系,请教各位~
解决方案 »
- sybase sql anywhere5.5谁有
- 烦人的mysql ERROR 2005 错误,是否有人遇到过
- 怎么能够在My.ini里面设置SET GLOBAL event_scheduler = 1;
- 数据库建触发器的问题
- mysql 触发器问题,求救啊?
- mysql trigger 不应该的死循环
- 连接mysql数据库提示host'test'is not allowed to connect to this mysql server
- 查询,插入问题,望高手帮助,谢谢!
- mysql关联查询
- mysql Truncated incorrect DOUBLE value: ''
- 数据库中浮点型的数据乘法存储处理对数据精度的影响?
- 谁帮忙给小弟解决一下问题啊?
如果raw和product的字段比较少,本来可以放在一张表里面的。
不知道楼上的是否明白。
表达能力一般,抱歉~
数据文件pathRaw(数据文件pathProduct暂假定和数据文件pathRaw的内容一样)内容如下:
20.1 20.2 32.1 20.1
42.1 20.1 42.5 23.1
42.1 20.1 42.5 23.1数据存入后要求的结果:
basic表:
id rawId productId
1 11 21
2 12 22
3 13 23raw表
rawId raw1 raw2 raw3 raw4
11 20.1 20.2 32.1 20.1
12 42.1 20.1 42.5 23.1
13 42.1 20.1 42.5 23.1product表
productId product1 product2 product3 product4
21 20.1 20.2 32.1 20.1
22 42.1 20.1 42.5 23.1
23 42.1 20.1 42.5 23.1
现有两个数据文件pathRaw和pathProduct,要把数据存入到三张表中(其中一张仅起到连接的作用),因为数据量的原因,现将两个数据表的结构和内容进行简化,简化后内容如下:
数据文件pathRaw的内容: 数据文件pathProduct的内容:
20.1 20.2 32.1 20.1 35.4 33.5
42.1 20.1 42.5 23.1 25.1 39.5
35.2 51.6 33.4 25.8 44.1 42.5数据存入后要求的结果:
basic表: raw表 product表
id rawId productId rawId raw1 raw2 raw3 raw4 productId product1 product2
1 11 21 11 20.1 20.2 32.1 20.1 21 35.4 33.5
2 12 22 12 42.1 20.1 42.5 23.1 22 25.1 39.5
3 13 23 13 35.2 51.6 33.4 25.8 23 44.1 42.59楼问的id、rawId、productId之间的关系是指数据表建立后,通过数据表查询可以得到如下例的结果:
1 20.1 20.2 32.1 20.1 35.4 33.5
2 42.1 20.1 42.5 23.1 25.1 39.5
3 35.2 51.6 33.4 25.8 44.1 42.5不知道这回我有没有说明白~还请各位海涵
a a a
b b b
可能是
a b c
d e f
就是这个意思~
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
create table raw
(
rawId int not null auto_increment,
raw1 float,
raw2 float,
raw3 float,
raw4 float,
primary key (rawId)
)create table product
(
productId int not null auto_increment,
product1 float,
product2 float,
primary key (productId)
)create table basic
(
id int not null auto_increment,
rawId int ,
productId int,
primary key (id),
foreign key (rawId) references raw(rawId),
foreign key (productId) references product(productId)
)/*以下是要存入数据表的数据文件的内容
文件pathRaw:
20.1,20.2,32.1,20.1
42.1,20.1,42.5,23.1
35.2,51.6,33.4,25.8
文件pathProduct:
35.4,33.5
25.1,39.5
44.1,42.5
*//*以下的语句仅仅是为了显示出数据存入以后各个数据表的内容,并非是所要解决问题的方案*/
/*raw从1开始自增*/
insert into raw select null,20.1,20.2,32.1,20.1;
insert into raw select null,42.1,20.1,42.5,23.1;
insert into raw select null,35.2,51.6,33.4,25.8;
/*这里故意改变自增的开始数字*/
insert into product select null,0,0;
insert into product select null,0,0;
delete from product;
/*从3开始自增*/
insert into product select null,35.4,33.5;
insert into product select null,25.1,39.5;
insert into product select null,44.1,42.5;
/*这里的语句不知道怎么写,所以就直接写出id的数字,按理是通过查询获得要插入的id*/
insert into basic select null, 1, 3;
insert into basic select null, 2, 4;
insert into basic select null, 3, 5;所要求助的问题是怎样通过导入pathRaw和pathProduct两个文件,达到以上红色语句执行以后实现的效果。麻烦给出具体一点的代码~