合并不同表的部分

时间:2018-10-18 19:10:39

标签: sql-server

嗨,我是sql的新手,只需要一点帮助。

说我有以下表格:

PrsDetails

ID  Name  Age Gen St. Co.
1   sdl   15  M   VA  US
2   slkd  14  F   TX  US
3   slkdd 17  F   VA  US
3   sldks 15  M   UP  IN
...

StDet

StateAbv  State         Reg  Co
VA        Virginia      SE   US
TX        Texas         SC   US
UP        Uttar Pradesh N    IN
...

CoDet

CountryAbv   Country         Continent
US           United States   North America
IN           India           Asia
CH           China           Asia
...

我如何为德克萨斯州的所有人提供一张新桌子,如下所示:

ID    Name      Age   Gen   State    Reg    Country   Continent
2     slkd      14    F     Texas    SC     US        North America
...

基本上,我现在正在做的是:

CREATE TABLE PeopleFromTexas (
ID int,
Name varChar(10),
Age int,
Gen varChar(1),
State varChar(30),
Reg varChar(4),
Country varChar(70)
Continent varChar(60)

);


INSERT INTO PeopleFromTexas
SELECT
PrsDetails.ID,
PrsDetails.Name,
PrsDetails.Age,
PrsDetails.Gen,
StDet.State,
StDet.Reg,
CoDet.Country,
CoDet.Continent

FROM
PrsDetails,
StDet,
CoDet

WHERE 
State = 'Texas'

但这无法正常工作,我不确定该怎么做。

0 个答案:

没有答案