首页 文章

使用SQL Server中的某些值更新表列

提问于
浏览
-1

我需要一些帮助或指导 .

我有这种情况,我在第一个表中没有主键:

County, 
Gender,
EconomyName, 
HighestEducation, 
HighestEducationCount,
EconomyCount

在第二张表中,我有

County, 
Gender, 
HighestEducation, 
HighestEducationCount

我想从第二个表值更新第一个表( HighestEducaiion, HighestEducationCount ) .

没有钥匙怎么办呢?以下是示例数据,EconStat,EduStatu在表1中为空白 .

County  Year    Gender  AgeDetails      EconStat    EducStatu   AgeCnt  EconCnt EduCnt
Carlow  2006    Male    Total persons                           20193   0       0
Carlow  2006    Male    Total whose                             17215   0       0
Carlow  2006    Male    Under 15 years                          2179    0       0
Carlow  2006    Male    15 years                                1366    0       0
Carlow  2006    Male    16 years                                2369    0       0
Carlow  2006    Male    17 years                                1767    0       0
Carlow  2006    Male    18 years                                2485    0       0

在第二个表中

County  Year    Gender  EducStatu                                   EduCnt
Carlow  2006    Male    Total education ceased and not ceased       20193
Carlow  2006    Male    Total whose full-time education has ceased  17215
Carlow  2006    Male    Primary (incl. no formal education)         3536
Carlow  2006    Male    Lower secondary                             4408

注意:总是少数据在第二个表中Result应如下所示

郡年性别年龄详细信息EconStat EducStatu AgeCnt EconCnt EduCnt Carlow 2006男性总人数完全停止且未停止20193 0 20193 Carlow 2006男性总数全日制教育已停止17215 0 17215 Carlow 2006男性未满15岁小学(包括否)正规教育)2179 0 3536 Carlow 2006男15年初中1366 0 4408 Carlow 2006男16年2369 0 0 Carlow 2006男17年1767 0 0 Carlow 2006男18年2485 0 0

1 回答

  • 0

    County,Year和Gender列的组合不是唯一的 . 在示例数据中,它们对两个列中的所有行都具有完全相同的值集 . 所以你不能根据它们做任何操作 .

    在第二列中,您将留下两列--EducStatu和EduCnt . 根据数据,EducStatu是区分第二个表中行的列(除了该表中前三列的组合) . 但是你已经提到EduStatu在第一个表中是空白的 . 因此,您在第一个和第二个表之间没有任何链接(通过列) . 根据您在此处提供的数据,无法将第二个表中的数据实际汇总到第一个表中的有意义数据 . 除非你在两个表中都有更多列,否则你运气不好 .

相关问题