如何将表的一列复制到PostgreSQL中比较相同ID的另一表的列中
问题描述:
我需要将ref_id1从table1复制到table2中的ref_id2列,这两个匹配的项将是:id(相同的列名),a_ref1和& b_ref1(列名不同,但数值相同)。
I need to copy ref_id1 from table1 TO the column ref_id2 in the table2 the two things matching will be : id (same column name), a_ref1 & b_ref1 (column names are different but numerical value will be identical).
Table1
ID ref_id1 a_ref1
9 2.3456762498; 1367602349
9 1.61680784158; 1367653785
9 2.63461385408; 1367687746
9 0; 1367688520
9 0.780442217152; 1367740313
9 3.18328461662; 1367773889
9 0.775471247616; 1367774978
Table2
ID b_ref1 ref_id2
9 1367602349;
9 1367740313;
9 1367774978;
2 1357110511;
2 1357186899;
2 1357195928;
2 1357199525;
概括地说,需要通过将id和a_ref1与b_ref1进行比较来将ref_id1复制到ref_id2,请让我知道
In a nutshell need to copy ref_id1 to ref_id2 by comparing id and a_ref1 with b_ref1, Please let me know how to do that.
答
UPDATE public.clean_trips_byobu
SET trip_dist = clean_trips.bktp_mt_total
FROM public.clean_trips
WHERE public.clean_trips.obu_id = clean_trips_byobu.obu_id
AND clean_trips.bktp_trip_id = clean_trips_byobu.trip_id;
希望它对您有用。