SQL表映射

时间:2016-09-16 07:21:39

标签: mysql sql-server-2008

我有一张包含超过10万个六位数CIP代码和相关标题的表格:

SixDigitCIPTable:

SixDigitCIPCode | SixDigitCIPTitle
========================
01.0000 | Agriculture, General
01.0102 | Agribusiness/Agricultural Business Operations
01.0201 | Agricultural Mechanization, General
03.0501 | Forestry, General
05.0112 | South Asian Studies

我需要用两位数和四位数的CIP代码和标题来映射它。 四位数的CIP表就像,

FourDigitCIPTable:

FourDigitCIPCode    FourDigitCIPTitle
=====================================
01.00   | Agriculture, General
01.01   | Agricultural Business and Management
01.02   | Agricultural Mechanization
03.05   | Forestry
05.01   | Area Studies

TwoDigitCIPTable:

TwoDigitCIPCode | TwoDigitCIPTitle
===================================
01  | Agriculture, Agriculture Operations, And Related Sciences
01  | Agriculture, Agriculture Operations, And Related Sciences
01  | Agriculture, Agriculture Operations, And Related Sciences
03  | Natural Resources And Conservation
05  | Area, Ethnic, Cultural, Gender, And Group Studies

我已经在三个不同的SQL表中加载了每个两位,四位和六位CIP查找值。 我需要在SixDigitCIPTable中插入两位数和四位CIP细节以及相应的值。

例如,

SixDigitCIPTable的第一条记录是,

01.0000 | Agriculture, General

所以两位数代码将为01,同时将这两位数字代码映射到TwoDigitCIPTable中,记录到地图是,

01  | Agriculture, Agriculture Operations, And Related Sciences 

和四位数代码将是01.00,同时将这个四位数代码映射到FourDigitCIPTable中的记录到地图是,

01.00   | Agriculture, General

所以在SixDigitCIPTable中插入两位和四位数代码后,第一条记录应该是,

01  | Agriculture, Agriculture Operations, And Related Sciences | 01.00 | Agriculture, General |    01.0000 | Agriculture, General

最后SixDigitCIPTable应该是,

TwoDigitCIPCode | TwoDigitCIPTitle  | FourDigitCIPCode | FourDigitCIPTitle  | SixDigitCIPCode   | SixDigitCIPTitle
=======================================================================
01  | Agriculture, Agriculture Operations, And Related Sciences | 01.00 | Agriculture, General |    01.0000 | Agriculture, General
01  | Agriculture, Agriculture Operations, And Related Sciences | 01.01  | Agricultural Business and Management |
01.0102 | Agribusiness/Agricultural Business Operations
01  | Agriculture, Agriculture Operations, And Related Sciences | 01.02  
| Agricultural Mechanization | 01.0201  | Agricultural Mechanization, General
03  | Natural Resources And Conservation | 03.05    | Forestry  3.0501  | Forestry, General
05  | Area, Ethnic, Cultural, Gender, And Group Studies | 05.01 | Area Studies  |05.0112 | South Asian Studies

在SQL中是否有可能这样做?

0 个答案:

没有答案