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

在SQL Server中使用某些值更新表列,sql,sql-server,tsql,Sql,Sql Server,Tsql,我需要一些帮助或指导 在这种情况下,第一个表中没有主键: County, Gender, EconomyName, HighestEducation, HighestEducationCount, EconomyCount 在第二张桌子上,我有 County, Gender, HighestEducation, HighestEducationCount 我想从第二个表值更新第一个表(highesteducation,HighestEducationCount) 没有钥匙怎么办?

我需要一些帮助或指导

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

County, 
Gender,
EconomyName, 
HighestEducation, 
HighestEducationCount,
EconomyCount
在第二张桌子上,我有

County, 
Gender, 
HighestEducation, 
HighestEducationCount
我想从第二个表值更新第一个表(
highesteducation,HighestEducationCount

没有钥匙怎么办?以下是示例数据EconStat,Edustautu在表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
注意:第二个表中的数据总是较少 结果应该是这样的

县年份性别年龄详情经济统计教育 Carlow 2006年男性总人数总教育停止和未停止20193 0 20193 Carlow 2006年男性总数,其全日制教育已停止17215 0 17215 Carlow 2006年15岁以下男性小学(包括未接受正规教育)21790 3536 Carlow 2006男15岁初中1366 0 4408 Carlow 2006男16岁2369 0 0 Carlow 2006男17岁1767 0 0
Carlow 2006男性18岁24850

县、年和性别栏的组合不是唯一的。在示例数据中,两列中的所有行的值都完全相同。因此,您不能基于它们执行任何操作


在第二列中,剩下两列—EducStatu和EduCnt。从数据中,EducStatu是区分第二个表中的行的列(除了该表中前三列的组合)。但是你提到了Edustaui在第一个表中是空白的。因此,在第一个表和第二个表之间没有任何链接(通过列)。从您在这里提供的数据来看,无法实际地将第二个表中的数据汇总为第一个表中有意义的数据。除非两个表中都有更多的列,否则你就不走运了

你能给我们分享一些样本数据吗,这会很有帮助的。与表数据和所需的dataWell一样,如果您没有显式主键(为什么?!),那么您必须告诉我们组合在一起的哪些列唯一地标识每一行(例如,组成一个“隐含”主键)。如果您不能定义类似的内容,那么您就不可能正确地更新它。。。。如果两个表之间没有关联,那么如何更新它?当然。我将编辑问题。谢谢,我已经编辑了您的示例数据,以便以正确的格式显示。我也不会为了你的成绩而这么做。这一次是在你身上。我希望光标有另一个选项。我是这样想的