第一个表格如下: - Car_id
,Car_Model
,Car_type
car_id
是PK
第二个表格如下: - car_id
,job_number
,date
,current_dist
,Prev_dist
car_id
是FK
我希望使用car_id
和job_number
答案 0 :(得分:1)
在选择查询中代替job_number
,date
,current_dist
,Prev_dist
你应该给出要插入表格的实际值
INSERT INTO Test1 (car_id, job_number, [date], current_dist, Prev_dist)
SELECT car_id,
job_number,
[date],
current_dist,
prev_dist
FROM Test
WHERE car_id = value;
答案 1 :(得分:0)
查询将类似于
INSERT INTO second_Table (car_id, job_number, date, current_dist, Prev_dist)
SELECT car_id,
job_number,
[date],
current_dist,
prev_dist
FROM first_Table
WHERE car_id = value
在此查询job_number中,date,current_dist,prev_dist将具有实际值,car_id将来自first_Table
例如:假设job_number = 123,date =' 2015-12-08 05:52:53.717',current_dist = 123,prev_dist = 234.然后查询就像
INSERT INTO second_Table (car_id, job_number, date, current_dist, Prev_dist)
SELECT car_id,
123,
'2015-12-08 05:52:53.717',
123,
234
FROM first_Table
WHERE car_id = value
答案 2 :(得分:0)
在oracle中正常工作
在select query中代替job_number,date,current_dist,Prev_dist你应该给出要在表中插入的实际值
INSERT INTO Test1 (car_id, job_number, [date], current_dist, Prev_dist)
SELECT car_id,
job_number,
[date],
current_dist,
prev_dist
FROM Test
WHERE car_id = value;